[X] I have searched the Issue Tracker that this hasn't already been reported. (comment there if it has.)
Motivation
Currently, only tuple and subclasses of namedtuple are considered node types. Other subclasses of tuple should be manually registered as node type. Otherwise, they are opaque leaf type.
Struct sequence objects are the C equivalent of namedtuple() objects, i.e. a sequence whose items can also be accessed through attributes. To create a struct sequence, you first have to create a specific struct sequence type.
PyStructSequence types are also subclasses of tuple. They are widely used in Python standard libraries (e.g, time.struct_time) and other packages (e.g., torch.return_types.*).
It would be nice if we consider PyStructSequence types as internal node types by default.
Required prerequisites
Motivation
Currently, only
tuple
and subclasses ofnamedtuple
are considered node types. Other subclasses oftuple
should be manually registered as node type. Otherwise, they are opaque leaf type.In Python documentation Struct Sequence Objects:
PyStructSequence
types are also subclasses oftuple
. They are widely used in Python standard libraries (e.g,time.struct_time
) and other packages (e.g.,torch.return_types.*
).It would be nice if we consider
PyStructSequence
types as internal node types by default.Ref:
PyStructSequence
Solution
Add special handling of
PyStructSequence
subclasses in C extensions as we did fornamedtuple
.A snippet I posted in What’s the best way to check if a type is
PyStructSequence
:Alternatives
Keep current API unchanged. Users need to register the
PyStructSequence
types manually.Additional context
No response