pytorch/torch/_export/serde
Xuehai Pan a10b765bf1 [pytree] add APIs to determine a class is a namedtuple or PyStructSequence (#113257)
Changes in this PR:

1. Add `is_structseq` and `is_structseq_class` functions to determine a object or a class is PyStructSequence.
2. Add a generic class `structseq` which can be used as the registration key for PyStructSequence types like `namedtuple` for Named Tuple types.
3. Change `is_namedtuple` to accept subclasses of namedtuple to be namedtuple. Before this PR, only namedtuple class directly created by `collections.namedtuple` or `typing.NamedTuple` were namedtuple classes while their subclasses were not. This PR makes `is_namedtuple` return true for subclasses of namedtuple class.

Resolves #75982. New tests are included in this PR.

- #75982

Pull Request resolved: https://github.com/pytorch/pytorch/pull/113257
Approved by: https://github.com/zou3519
2025-04-01 10:40:43 +00:00
..
gen-cpp2 [export][ez] Fix forward D67044185 (#143193) 2024-12-13 16:06:42 +00:00
__init__.py
aoti_schema.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
dynamic_shapes.py [export] refactor _Dim into Dim (#149891) 2025-03-28 06:19:03 +00:00
export_schema.thrift [export] Sync aoti schema to schema.py (#148017) 2025-02-27 21:46:11 +00:00
schema_check.py Fix "invalid application of 'sizeof' to an incomplete type" (#148854) 2025-03-11 00:40:00 +00:00
schema.py [export] Sync aoti schema to schema.py (#148017) 2025-02-27 21:46:11 +00:00
schema.yaml [export] Sync aoti schema to schema.py (#148017) 2025-02-27 21:46:11 +00:00
serialize.py [pytree] add APIs to determine a class is a namedtuple or PyStructSequence (#113257) 2025-04-01 10:40:43 +00:00
union.py [BE]: Enable ruff SLOT checks (#146276) 2025-02-04 19:18:23 +00:00