Message207991
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. |
|
Date |
User |
Action |
Args |
2014-01-13 01:12:54 | abarnert | set | recipients:
+ abarnert |
2014-01-13 01:12:54 | abarnert | set | messageid: <1389575574.46.0.402404595733.issue20230@psf.upfronthosting.co.za> |
2014-01-13 01:12:54 | abarnert | link | issue20230 messages |
2014-01-13 01:12:54 | abarnert | create | |
|