Author tim.peters
Recipients docs@python, tim.peters
Date 2019-09-10.22:05:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The Glossary has this entry:

struct sequence
A tuple with named elements. Struct sequences expose an interface similar to named tuple in that elements can be accessed either by index or as an attribute. However, they do not have any of the named tuple methods like _make() or _asdict(). Examples of struct sequences include sys.float_info and the return value of os.stat().

It's trying to document the internal CPython implementation `structseq` detail, a class of which can only be created from the C API (no Python interface is exposed).

But the glossary _also_ has an entry for "named tuple", and the docs just above are confusing that for the related but distinct `collections.namedtuple` facility, which does allow creating a named tuple class from Python, but is NOT the only kind of "named tuple".

This is a mess ;-)

I suggest:

- Throw away the "struct sequence" glossary entry, and remove all references to it from the docs.

- Use "named tuple" everywhere instead.

- Clarify the "named tuple" docs to make clear that it applies to any class that supports tuple methods and also named elements.

- Make clear that `collections.namedtuple` classes are "named tuples" classes, but not the only kind, and support a number of methods beyond what's required for "named tuples".

- Optionally, effectively expose `structseq` to Python code, so that users have one obvious way to create their own bare-bones named tuple types.

- I'd prefer to insist that for any named tuple class C,

  issubclass(C, tuple)
  is True.  That's true now of structseqs and collections.namedtuples, and is a sane way to make clear that they must support all tuple methods.
I'd mark this as "newcomer friendly", except it's likely to become a bikeshedding nightmare ;-)
Date User Action Args
2019-09-10 22:05:24tim.peterssetrecipients: + tim.peters, docs@python
2019-09-10 22:05:24tim.peterssetmessageid: <>
2019-09-10 22:05:24tim.peterslinkissue38096 messages
2019-09-10 22:05:24tim.peterscreate