| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -739,17 +739,28 @@ Glossary | |||
| 739 | 739 | also :term:`immutable`. | |
| 740 | 740 | ||
| 741 | 741 | named tuple | |
| 742 | - Any tuple-like class whose indexable elements are also accessible using | ||
| 743 | - named attributes (for example, :func:`time.localtime` returns a | ||
| 744 | - tuple-like object where the *year* is accessible either with an | ||
| 745 | - index such as ``t[0]`` or with a named attribute like ``t.tm_year``). | ||
| 746 | - | ||
| 747 | - A named tuple can be a built-in type such as :class:`time.struct_time`, | ||
| 748 | - or it can be created with a regular class definition. A full featured | ||
| 749 | - named tuple can also be created with the factory function | ||
| 750 | - :func:`collections.namedtuple`. The latter approach automatically | ||
| 751 | - provides extra features such as a self-documenting representation like | ||
| 752 | - ``Employee(name='jones', title='programmer')``. | ||
| 742 | + The term "named tuple" applies to any type or class that inherits from | ||
| 743 | + tuple and whose indexable elements are also accessible using named | ||
| 744 | + attributes. The type or class may have other features as well. | ||
| 745 | + | ||
| 746 | + Several built-in types are named tuples, including the values returned | ||
| 747 | + by :func:`time.localtime` and :func:`os.stat`. Another example is | ||
| 748 | + :data:`sys.float_info`:: | ||
| 749 | + | ||
| 750 | + >>> sys.float_info[1] # indexed access | ||
| 751 | + 1024 | ||
| 752 | + >>> sys.float_info.max_exp # named field access | ||
| 753 | + 1024 | ||
| 754 | + >>> isinstance(sys.float_info, tuple) # kind of tuple | ||
| 755 | + True | ||
| 756 | + | ||
| 757 | + Some named tuples are built-in types (such as the above examples). | ||
| 758 | + Alternatively, a named tuple can be created from a regular class | ||
| 759 | + definition that inherits from :class:`tuple` and that defines named | ||
| 760 | + fields. Such as class can be written by hand or it can be created with | ||
| 761 | + the factory function :func:`collections.namedtuple`. The latter | ||
| 762 | + technique also adds some extra methods that may not be found in | ||
| 763 | + hand-written or built-in named tuples. | ||
| 753 | 764 | ||
| 754 | 765 | namespace | |
| 755 | 766 | The place where a variable is stored. Namespaces are implemented as | |
@@ -1032,14 +1043,6 @@ Glossary | |||
| 1032 | 1043 | an :term:`expression` or one of several constructs with a keyword, such | |
| 1033 | 1044 | as :keyword:`if`, :keyword:`while` or :keyword:`for`. | |
| 1034 | 1045 | ||
| 1035 | - struct sequence | ||
| 1036 | - A tuple with named elements. Struct sequences expose an interface similar | ||
| 1037 | - to :term:`named tuple` in that elements can be accessed either by | ||
| 1038 | - index or as an attribute. However, they do not have any of the named tuple | ||
| 1039 | - methods like :meth:`~collections.somenamedtuple._make` or | ||
| 1040 | - :meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences | ||
| 1041 | - include :data:`sys.float_info` and the return value of :func:`os.stat`. | ||
| 1042 | - | ||
| 1043 | 1046 | text encoding | |
| 1044 | 1047 | A codec which encodes Unicode strings to bytes. | |
| 1045 | 1048 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -408,7 +408,7 @@ always available. | |||
| 408 | 408 | ||
| 409 | 409 | .. data:: flags | |
| 410 | 410 | ||
| 411 | - The :term:`struct sequence` *flags* exposes the status of command line | ||
| 411 | + The :term:`named tuple` *flags* exposes the status of command line | ||
| 412 | 412 | flags. The attributes are read only. | |
| 413 | 413 | ||
| 414 | 414 | ============================= ============================= | |
@@ -450,7 +450,7 @@ always available. | |||
| 450 | 450 | ||
| 451 | 451 | .. data:: float_info | |
| 452 | 452 | ||
| 453 | - A :term:`struct sequence` holding information about the float type. It | ||
| 453 | + A :term:`named tuple` holding information about the float type. It | ||
| 454 | 454 | contains low level information about the precision and internal | |
| 455 | 455 | representation. The values correspond to the various floating-point | |
| 456 | 456 | constants defined in the standard header file :file:`float.h` for the 'C' | |
@@ -790,7 +790,7 @@ always available. | |||
| 790 | 790 | ||
| 791 | 791 | .. data:: hash_info | |
| 792 | 792 | ||
| 793 | - A :term:`struct sequence` giving parameters of the numeric hash | ||
| 793 | + A :term:`named tuple` giving parameters of the numeric hash | ||
| 794 | 794 | implementation. For more details about hashing of numeric types, see | |
| 795 | 795 | :ref:`numeric-hash`. | |
| 796 | 796 | ||
@@ -838,7 +838,7 @@ always available. | |||
| 838 | 838 | ||
| 839 | 839 | This is called ``hexversion`` since it only really looks meaningful when viewed | |
| 840 | 840 | as the result of passing it to the built-in :func:`hex` function. The | |
| 841 | - :term:`struct sequence` :data:`sys.version_info` may be used for a more | ||
| 841 | + :term:`named tuple` :data:`sys.version_info` may be used for a more | ||
| 842 | 842 | human-friendly encoding of the same information. | |
| 843 | 843 | ||
| 844 | 844 | More details of ``hexversion`` can be found at :ref:`apiabiversion`. | |
@@ -890,7 +890,7 @@ always available. | |||
| 890 | 890 | ||
| 891 | 891 | .. data:: int_info | |
| 892 | 892 | ||
| 893 | - A :term:`struct sequence` that holds information about Python's internal | ||
| 893 | + A :term:`named tuple` that holds information about Python's internal | ||
| 894 | 894 | representation of integers. The attributes are read only. | |
| 895 | 895 | ||
| 896 | 896 | .. tabularcolumns:: |l|L| | |
@@ -1480,7 +1480,7 @@ always available. | |||
| 1480 | 1480 | ||
| 1481 | 1481 | .. data:: thread_info | |
| 1482 | 1482 | ||
| 1483 | - A :term:`struct sequence` holding information about the thread | ||
| 1483 | + A :term:`named tuple` holding information about the thread | ||
| 1484 | 1484 | implementation. | |
| 1485 | 1485 | ||
| 1486 | 1486 | .. tabularcolumns:: |l|p{0.7\linewidth}| | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2002,8 +2002,8 @@ platform-independent fashion. (Contributed by Ross Lagerwall in | |||
| 2002 | 2002 | sys | |
| 2003 | 2003 | --- | |
| 2004 | 2004 | ||
| 2005 | - The :mod:`sys` module has a new :data:`~sys.thread_info` :term:`struct | ||
| 2006 | - sequence` holding information about the thread implementation | ||
| 2005 | + The :mod:`sys` module has a new :data:`~sys.thread_info` :term:`named | ||
| 2006 | + tuple` holding information about the thread implementation | ||
| 2007 | 2007 | (:issue:`11223`). | |
| 2008 | 2008 | ||
| 2009 | 2009 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1849,7 +1849,7 @@ Python's default implementation to a SipHash implementation on platforms that | |||
| 1849 | 1849 | have a 64 bit data type. Any performance differences in comparison with the | |
| 1850 | 1850 | older FNV algorithm are trivial. | |
| 1851 | 1851 | ||
| 1852 | - The PEP adds additional fields to the :attr:`sys.hash_info` struct sequence to | ||
| 1852 | + The PEP adds additional fields to the :attr:`sys.hash_info` named tuple to | ||
| 1853 | 1853 | describe the hash algorithm in use by the currently executing binary. Otherwise, | |
| 1854 | 1854 | the PEP does not alter any existing CPython APIs. | |
| 1855 | 1855 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,7 @@ static PyTypeObject FloatInfoType; | |||
| 43 | 43 | PyDoc_STRVAR(floatinfo__doc__, | |
| 44 | 44 | "sys.float_info\n\ | |
| 45 | 45 | \n\ | |
| 46 | - A structseq holding information about the float type. It contains low level\n\ | ||
| 46 | + A named tuple holding information about the float type. It contains low level\n\ | ||
| 47 | 47 | information about the precision and internal representation. Please study\n\ | |
| 48 | 48 | your system's :file:`float.h` for more information."); | |
| 49 | 49 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5771,7 +5771,7 @@ static PyTypeObject Int_InfoType; | |||
| 5771 | 5771 | PyDoc_STRVAR(int_info__doc__, | |
| 5772 | 5772 | "sys.int_info\n\ | |
| 5773 | 5773 | \n\ | |
| 5774 | - A struct sequence that holds information about Python's\n\ | ||
| 5774 | + A named tuple that holds information about Python's\n\ | ||
| 5775 | 5775 | internal representation of integers. The attributes are read only."); | |
| 5776 | 5776 | ||
| 5777 | 5777 | static PyStructSequence_Field int_info_fields[] = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1162,7 +1162,7 @@ static PyTypeObject AsyncGenHooksType; | |||
| 1162 | 1162 | PyDoc_STRVAR(asyncgen_hooks_doc, | |
| 1163 | 1163 | "asyncgen_hooks\n\ | |
| 1164 | 1164 | \n\ | |
| 1165 | - A struct sequence providing information about asynhronous\n\ | ||
| 1165 | + A named tuple providing information about asynchronous\n\ | ||
| 1166 | 1166 | generators hooks. The attributes are read only."); | |
| 1167 | 1167 | ||
| 1168 | 1168 | static PyStructSequence_Field asyncgen_hooks_fields[] = { | |
@@ -1270,7 +1270,7 @@ static PyTypeObject Hash_InfoType; | |||
| 1270 | 1270 | PyDoc_STRVAR(hash_info_doc, | |
| 1271 | 1271 | "hash_info\n\ | |
| 1272 | 1272 | \n\ | |
| 1273 | - A struct sequence providing parameters used for computing\n\ | ||
| 1273 | + A named tuple providing parameters used for computing\n\ | ||
| 1274 | 1274 | hashes. The attributes are read only."); | |
| 1275 | 1275 | ||
| 1276 | 1276 | static PyStructSequence_Field hash_info_fields[] = { | |
@@ -2321,17 +2321,17 @@ builtin_module_names -- tuple of module names built into this interpreter\n\ | |||
| 2321 | 2321 | copyright -- copyright notice pertaining to this interpreter\n\ | |
| 2322 | 2322 | exec_prefix -- prefix used to find the machine-specific Python library\n\ | |
| 2323 | 2323 | executable -- absolute path of the executable binary of the Python interpreter\n\ | |
| 2324 | - float_info -- a struct sequence with information about the float implementation.\n\ | ||
| 2324 | + float_info -- a named tuple with information about the float implementation.\n\ | ||
| 2325 | 2325 | float_repr_style -- string indicating the style of repr() output for floats\n\ | |
| 2326 | - hash_info -- a struct sequence with information about the hash algorithm.\n\ | ||
| 2326 | + hash_info -- a named tuple with information about the hash algorithm.\n\ | ||
| 2327 | 2327 | hexversion -- version information encoded as a single integer\n\ | |
| 2328 | 2328 | implementation -- Python implementation information.\n\ | |
| 2329 | - int_info -- a struct sequence with information about the int implementation.\n\ | ||
| 2329 | + int_info -- a named tuple with information about the int implementation.\n\ | ||
| 2330 | 2330 | maxsize -- the largest supported length of containers.\n\ | |
| 2331 | 2331 | maxunicode -- the value of the largest Unicode code point\n\ | |
| 2332 | 2332 | platform -- platform identifier\n\ | |
| 2333 | 2333 | prefix -- prefix used to find the Python library\n\ | |
| 2334 | - thread_info -- a struct sequence with information about the thread implementation.\n\ | ||
| 2334 | + thread_info -- a named tuple with information about the thread implementation.\n\ | ||
| 2335 | 2335 | version -- the version of this interpreter as a string\n\ | |
| 2336 | 2336 | version_info -- version information as a named tuple\n\ | |
| 2337 | 2337 | " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,7 +147,7 @@ PyThread_tss_is_created(Py_tss_t *key) | |||
| 147 | 147 | PyDoc_STRVAR(threadinfo__doc__, | |
| 148 | 148 | "sys.thread_info\n\ | |
| 149 | 149 | \n\ | |
| 150 | - A struct sequence holding information about the thread implementation."); | ||
| 150 | + A named tuple holding information about the thread implementation."); | ||
| 151 | 151 | ||
| 152 | 152 | static PyStructSequence_Field threadinfo_fields[] = { | |
| 153 | 153 | {"name", "name of the thread implementation"}, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments