[dynamo] Support types.SimpleNamespace (#193719)
## Summary
Dynamo has no model of `types.SimpleNamespace`. Its C `tp_new` is not on the allowlist
in `UserDefinedClassVariable.supported_c_new_functions`, so constructing one
graph-breaks before anything downstream runs, and all 17 tests in
`SimpleNamespaceTests` are on the expected-failure list because of it.
The type keeps a plain instance dict and inherits `__getattribute__`, `__setattr__` and
`__delattr__` from `object`, so attribute access, `__dict__` and `vars()` come from the
existing `UserDefinedObjectVariable` machinery once construction is allowed. This adds a
`SimpleNamespaceVariable` modelling the four C slots with no Python source to inline:
`tp_init`, `tp_repr`, `tp_richcompare` and `__replace__`.
Removes 16 of the 17 expected-failure markers. `test_pickle` keeps its marker, since it
needs `_pickle.dumps`, which is on the skip list.
Draft, and no linked issue yet.
## Test Plan
PYTORCH_TEST_WITH_DYNAMO=1 python test/cpython/v3_13/test_types.py
python test/dynamo/test_user_defined_object.py
18 new tests ported from CPython's `SimpleNamespaceTests`, all of which fail on the
parent commit. Also ran test_repros, test_functions, test_dicts and the
repr/str/len/contains/getitem/tp_slots/tp_richcompare suites.
## Checklist
- [x] Passes lint (`lintrunner -a`)
- [x] Added/updated tests
- [ ] Updated documentation (if applicable)
- [ ] Included benchmark results (for PRs impacting perf)
## BC-breaking?
No.
---
This PR was written with the assistance of Claude (Anthropic).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/193719
Approved by: https://github.com/Skylion007, https://github.com/guilhermeleobas G
gabrielfruet committed
91655aa6a90a357ee8b47a4ac15ec7257f505526
Parent: cf8577d
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com>
on 8/25/2026, 3:11:24 AM