pytorch/torch/_export
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
..
db PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
pass_infra PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
passes Suppress more warnings (#149833) 2025-04-01 05:33:04 +00:00
serde [pytree] add APIs to determine a class is a namedtuple or PyStructSequence (#113257) 2025-04-01 10:40:43 +00:00
__init__.py PEP585: More UP006 fixes (#146392) 2025-02-20 06:18:13 +00:00
converter.py [export] refactor DimHints for type errors (#149424) 2025-03-19 18:51:07 +00:00
error.py Fix global flake8 issues (#124771) 2024-04-26 15:35:53 +00:00
non_strict_utils.py [export] min/max ranges for dim hints (#149590) 2025-03-31 21:32:20 +00:00
pass_base.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
tools.py PEP585 update - torch/_export (#145138) 2025-01-19 18:48:35 +00:00
utils.py preserve custom meta in placeholders (#149661) 2025-03-21 19:09:38 +00:00
verifier.py Support subclass constructor capturing in export (#147014) 2025-03-16 18:19:19 +00:00
wrappers.py Support subclass constructor capturing in export (#147014) 2025-03-16 18:19:19 +00:00