This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abarnert
Recipients abarnert
Date 2014-01-13.01:12:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389575574.46.0.402404595733.issue20230@psf.upfronthosting.co.za>
In-reply-to
Content
A PyStructSequence type doesn't expose its field names in any way to Python code (except indirectly, via the repr, which you could parse if you really wanted to…).

The docs claim that "Struct sequence objects are the C equivalent of namedtuple() objects", so it seems like the obvious way to expose them is the exact same way namedtuple types do—as a class attribute named "_fields".

Also, in #7796, and in a recent thread on python-ideas, multiple people suggested that "named tuple" is a protocol, not a type, and duck typing on _fields is the obvious way to detect types matching that protocol.

Only the "sequence fields" need to be exposed—fields that don't match up to sequence indices aren't named tuple fields, they're just extra instance attributes (that don't even show up in the repr).

Patch included. For the tests, I tested the fields in struct_time and stat_result in effectively the same way test_repr tests their repr, so it should pass on all the same platforms/builds.
History
Date User Action Args
2014-01-13 01:12:54abarnertsetrecipients: + abarnert
2014-01-13 01:12:54abarnertsetmessageid: <1389575574.46.0.402404595733.issue20230@psf.upfronthosting.co.za>
2014-01-13 01:12:54abarnertlinkissue20230 messages
2014-01-13 01:12:54abarnertcreate