-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-105936: Properly update closure cells for __setattr__ and __detattr__ in frozen dataclasses with slots
#144021
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
base: main
Are you sure you want to change the base?
gh-105936: Properly update closure cells for __setattr__ and __detattr__ in frozen dataclasses with slots
#144021
Conversation
|
Thanks! For the test you can do something like that in the original fix, https://github.com/python/cpython/pull/137047/files#diff-212e368b34eb9b134f87e765787d6d26b747235a358e13da8922f83861c0d676 . |
fdc81bb to
a6de29b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
__setattr__ and __detattr__ in frozen dataclasses with slots__setattr__ and __detattr__ in frozen dataclasses with slots
Misc/NEWS.d/next/Library/2026-01-19-21-23-18.gh-issue-105936.dGrzjM.rst
Outdated
Show resolved
Hide resolved
|
While this PR is not merged, should AKCS be updated? |
|
If I remember correctly the latest policy on Misc/ACKS is that people can add themselves if they want but it's not required. The file is a pain to keep fully correct and sort of redundant with |
Specifying
frozen=Truefor a dataclass adds methods__setattr__and__detattr__to it. These methods reference the class via closure. Ifslots=Trueis also present, then the class is recreated with slots with all methods being copied. Notably, every method referencing the old class via closure in variable__class__is properly updated, but__setattr__and__detattr__reference the old class viacls; hence, they are still referencing the old class instead of the new one. This PR fixes this issue.__setattr__and__delattr__does not work. #105936Additional details:
The issue is present in Python as early as in 3.10. This PR must be backported to 3.14 and possibly 3.13.
Originally this PR was referencing gh-135228, but soon I realized that the issue is not connected to regression in 3.14. There is an older PR #105937 that fixes the issue, but it is heavily outdated.