Skip to content

Commit b7a310d

Browse files
pgansslerhettinger
authored andcommitted
bpo-38096: Clean up the "struct sequence" / "named tuple" docs (GH-15895) (GH-15962)
1 parent 8892a1d commit b7a310d

File tree

8 files changed

+40
-37
lines changed

8 files changed

+40
-37
lines changed

Doc/glossary.rst

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,28 @@ Glossary
735735
also :term:`immutable`.
736736

737737
named tuple
738-
Any tuple-like class whose indexable elements are also accessible using
739-
named attributes (for example, :func:`time.localtime` returns a
740-
tuple-like object where the *year* is accessible either with an
741-
index such as ``t[0]`` or with a named attribute like ``t.tm_year``).
742-
743-
A named tuple can be a built-in type such as :class:`time.struct_time`,
744-
or it can be created with a regular class definition. A full featured
745-
named tuple can also be created with the factory function
746-
:func:`collections.namedtuple`. The latter approach automatically
747-
provides extra features such as a self-documenting representation like
748-
``Employee(name='jones', title='programmer')``.
738+
The term "named tuple" applies to any type or class that inherits from
739+
tuple and whose indexable elements are also accessible using named
740+
attributes. The type or class may have other features as well.
741+
742+
Several built-in types are named tuples, including the values returned
743+
by :func:`time.localtime` and :func:`os.stat`. Another example is
744+
:data:`sys.float_info`::
745+
746+
>>> sys.float_info[1] # indexed access
747+
1024
748+
>>> sys.float_info.max_exp # named field access
749+
1024
750+
>>> isinstance(sys.float_info, tuple) # kind of tuple
751+
True
752+
753+
Some named tuples are built-in types (such as the above examples).
754+
Alternatively, a named tuple can be created from a regular class
755+
definition that inherits from :class:`tuple` and that defines named
756+
fields. Such as class can be written by hand or it can be created with
757+
the factory function :func:`collections.namedtuple`. The latter
758+
technique also adds some extra methods that may not be found in
759+
hand-written or built-in named tuples.
749760

750761
namespace
751762
The place where a variable is stored. Namespaces are implemented as
@@ -1028,14 +1039,6 @@ Glossary
10281039
an :term:`expression` or one of several constructs with a keyword, such
10291040
as :keyword:`if`, :keyword:`while` or :keyword:`for`.
10301041

1031-
struct sequence
1032-
A tuple with named elements. Struct sequences expose an interface similar
1033-
to :term:`named tuple` in that elements can be accessed either by
1034-
index or as an attribute. However, they do not have any of the named tuple
1035-
methods like :meth:`~collections.somenamedtuple._make` or
1036-
:meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences
1037-
include :data:`sys.float_info` and the return value of :func:`os.stat`.
1038-
10391042
text encoding
10401043
A codec which encodes Unicode strings to bytes.
10411044

Doc/library/sys.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ always available.
324324

325325
.. data:: flags
326326

327-
The :term:`struct sequence` *flags* exposes the status of command line
327+
The :term:`named tuple` *flags* exposes the status of command line
328328
flags. The attributes are read only.
329329

330330
============================= =============================
@@ -366,7 +366,7 @@ always available.
366366

367367
.. data:: float_info
368368

369-
A :term:`struct sequence` holding information about the float type. It
369+
A :term:`named tuple` holding information about the float type. It
370370
contains low level information about the precision and internal
371371
representation. The values correspond to the various floating-point
372372
constants defined in the standard header file :file:`float.h` for the 'C'
@@ -716,7 +716,7 @@ always available.
716716

717717
.. data:: hash_info
718718

719-
A :term:`struct sequence` giving parameters of the numeric hash
719+
A :term:`named tuple` giving parameters of the numeric hash
720720
implementation. For more details about hashing of numeric types, see
721721
:ref:`numeric-hash`.
722722

@@ -764,7 +764,7 @@ always available.
764764

765765
This is called ``hexversion`` since it only really looks meaningful when viewed
766766
as the result of passing it to the built-in :func:`hex` function. The
767-
:term:`struct sequence` :data:`sys.version_info` may be used for a more
767+
:term:`named tuple` :data:`sys.version_info` may be used for a more
768768
human-friendly encoding of the same information.
769769

770770
More details of ``hexversion`` can be found at :ref:`apiabiversion`.
@@ -816,7 +816,7 @@ always available.
816816

817817
.. data:: int_info
818818

819-
A :term:`struct sequence` that holds information about Python's internal
819+
A :term:`named tuple` that holds information about Python's internal
820820
representation of integers. The attributes are read only.
821821

822822
.. tabularcolumns:: |l|L|
@@ -1423,7 +1423,7 @@ always available.
14231423

14241424
.. data:: thread_info
14251425

1426-
A :term:`struct sequence` holding information about the thread
1426+
A :term:`named tuple` holding information about the thread
14271427
implementation.
14281428

14291429
.. tabularcolumns:: |l|p{0.7\linewidth}|

Doc/whatsnew/3.3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,8 @@ platform-independent fashion. (Contributed by Ross Lagerwall in
20022002
sys
20032003
---
20042004

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
20072007
(:issue:`11223`).
20082008

20092009

Doc/whatsnew/3.4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ Python's default implementation to a SipHash implementation on platforms that
18491849
have a 64 bit data type. Any performance differences in comparison with the
18501850
older FNV algorithm are trivial.
18511851

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
18531853
describe the hash algorithm in use by the currently executing binary. Otherwise,
18541854
the PEP does not alter any existing CPython APIs.
18551855

Objects/floatobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static PyTypeObject FloatInfoType;
4343
PyDoc_STRVAR(floatinfo__doc__,
4444
"sys.float_info\n\
4545
\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\
4747
information about the precision and internal representation. Please study\n\
4848
your system's :file:`float.h` for more information.");
4949

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5424,7 +5424,7 @@ static PyTypeObject Int_InfoType;
54245424
PyDoc_STRVAR(int_info__doc__,
54255425
"sys.int_info\n\
54265426
\n\
5427-
A struct sequence that holds information about Python's\n\
5427+
A named tuple that holds information about Python's\n\
54285428
internal representation of integers. The attributes are read only.");
54295429

54305430
static PyStructSequence_Field int_info_fields[] = {

Python/sysmodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static PyTypeObject AsyncGenHooksType;
836836
PyDoc_STRVAR(asyncgen_hooks_doc,
837837
"asyncgen_hooks\n\
838838
\n\
839-
A struct sequence providing information about asynhronous\n\
839+
A named tuple providing information about asynchronous\n\
840840
generators hooks. The attributes are read only.");
841841

842842
static PyStructSequence_Field asyncgen_hooks_fields[] = {
@@ -943,7 +943,7 @@ static PyTypeObject Hash_InfoType;
943943
PyDoc_STRVAR(hash_info_doc,
944944
"hash_info\n\
945945
\n\
946-
A struct sequence providing parameters used for computing\n\
946+
A named tuple providing parameters used for computing\n\
947947
hashes. The attributes are read only.");
948948

949949
static PyStructSequence_Field hash_info_fields[] = {
@@ -1967,17 +1967,17 @@ builtin_module_names -- tuple of module names built into this interpreter\n\
19671967
copyright -- copyright notice pertaining to this interpreter\n\
19681968
exec_prefix -- prefix used to find the machine-specific Python library\n\
19691969
executable -- absolute path of the executable binary of the Python interpreter\n\
1970-
float_info -- a struct sequence with information about the float implementation.\n\
1970+
float_info -- a named tuple with information about the float implementation.\n\
19711971
float_repr_style -- string indicating the style of repr() output for floats\n\
1972-
hash_info -- a struct sequence with information about the hash algorithm.\n\
1972+
hash_info -- a named tuple with information about the hash algorithm.\n\
19731973
hexversion -- version information encoded as a single integer\n\
19741974
implementation -- Python implementation information.\n\
1975-
int_info -- a struct sequence with information about the int implementation.\n\
1975+
int_info -- a named tuple with information about the int implementation.\n\
19761976
maxsize -- the largest supported length of containers.\n\
19771977
maxunicode -- the value of the largest Unicode code point\n\
19781978
platform -- platform identifier\n\
19791979
prefix -- prefix used to find the Python library\n\
1980-
thread_info -- a struct sequence with information about the thread implementation.\n\
1980+
thread_info -- a named tuple with information about the thread implementation.\n\
19811981
version -- the version of this interpreter as a string\n\
19821982
version_info -- version information as a named tuple\n\
19831983
"

Python/thread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ PyThread_tss_is_created(Py_tss_t *key)
147147
PyDoc_STRVAR(threadinfo__doc__,
148148
"sys.thread_info\n\
149149
\n\
150-
A struct sequence holding information about the thread implementation.");
150+
A named tuple holding information about the thread implementation.");
151151

152152
static PyStructSequence_Field threadinfo_fields[] = {
153153
{"name", "name of the thread implementation"},

0 commit comments

Comments
 (0)