-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[dynamo, 3.8-3.9] support dataclass with frozen=True
in Python 3.8/3.9
#124393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/124393
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 4e7ddb8 with merge base 5677128 ( BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
frozen=True
in Python 3.8frozen=True
in Python 3.8/3.9
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…3.9 (pytorch#124393) Closes pytorch#114966 Frozen field assignment in `__init__` in Python 3.8-3.9: https://github.com/python/cpython/blob/f5bd65ed37bbccfa113438cf9e34feae6816ecb1/Lib/dataclasses.py#L402-L411 ```python import builtins BUILTINS = builtins def _field_assign(frozen, name, value, self_name): # If we're a frozen class, then assign to our fields in __init__ # via object.__setattr__. Otherwise, just use a simple # assignment. # # self_name is what "self" is called in this function: don't # hard-code "self", since that might be a field name. if frozen: return f'BUILTINS.object.__setattr__({self_name},{name!r},{value})' return f'{self_name}.{name}={value}' ``` Frozen field assignment in `__init__` in Python 3.10+: https://github.com/python/cpython/blob/812245ecce2d8344c3748228047bab456816180a/Lib/dataclasses.py#L436-L445 ```python __dataclass_builtins_object__ = object def _field_assign(frozen, name, value, self_name): # If we're a frozen class, then assign to our fields in __init__ # via object.__setattr__. Otherwise, just use a simple # assignment. # # self_name is what "self" is called in this function: don't # hard-code "self", since that might be a field name. if frozen: return f'__dataclass_builtins_object__.__setattr__({self_name},{name!r},{value})' return f'{self_name}.{name}={value}' ``` Pull Request resolved: pytorch#124393 Approved by: https://github.com/jansel
…3.9 (pytorch#124393) Closes pytorch#114966 Frozen field assignment in `__init__` in Python 3.8-3.9: https://github.com/python/cpython/blob/f5bd65ed37bbccfa113438cf9e34feae6816ecb1/Lib/dataclasses.py#L402-L411 ```python import builtins BUILTINS = builtins def _field_assign(frozen, name, value, self_name): # If we're a frozen class, then assign to our fields in __init__ # via object.__setattr__. Otherwise, just use a simple # assignment. # # self_name is what "self" is called in this function: don't # hard-code "self", since that might be a field name. if frozen: return f'BUILTINS.object.__setattr__({self_name},{name!r},{value})' return f'{self_name}.{name}={value}' ``` Frozen field assignment in `__init__` in Python 3.10+: https://github.com/python/cpython/blob/812245ecce2d8344c3748228047bab456816180a/Lib/dataclasses.py#L436-L445 ```python __dataclass_builtins_object__ = object def _field_assign(frozen, name, value, self_name): # If we're a frozen class, then assign to our fields in __init__ # via object.__setattr__. Otherwise, just use a simple # assignment. # # self_name is what "self" is called in this function: don't # hard-code "self", since that might be a field name. if frozen: return f'__dataclass_builtins_object__.__setattr__({self_name},{name!r},{value})' return f'{self_name}.{name}={value}' ``` Pull Request resolved: pytorch#124393 Approved by: https://github.com/jansel
ghstack-source-id: bf04ab7 Pull Request resolved: pytorch/pytorch#124393
Stack from ghstack (oldest at bottom):
TreeSpec
#124011frozen=True
in Python 3.8/3.9 #124393Closes #114966
Frozen field assignment in
__init__
in Python 3.8-3.9:https://github.com/python/cpython/blob/f5bd65ed37bbccfa113438cf9e34feae6816ecb1/Lib/dataclasses.py#L402-L411
Frozen field assignment in
__init__
in Python 3.10+:https://github.com/python/cpython/blob/812245ecce2d8344c3748228047bab456816180a/Lib/dataclasses.py#L436-L445
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang