| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
|
Thanks! For the test you can do something like that in the original fix, https://github.com/python/cpython/pull/137047/files#diff-212e368b34eb9b134f87e765787d6d26b747235a358e13da8922f83861c0d676 . |
Sorry, something went wrong.
|
While this PR is not merged, should AKCS be updated? |
Sorry, something went wrong.
|
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 git log, so there's been talk of getting rid of it but not sure anything concrete has changed yet. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM as well.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
|
Thanks @Prometheus3375 for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
…`__delattr__` in frozen dataclasses with slots (pythonGH-144021) (cherry picked from commit 8a398bf) Co-authored-by: Sviataslau <35541026+Prometheus3375@users.noreply.github.com>
|
Sorry, @Prometheus3375 and @gpshead, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker 8a398bfbbc6769f6cabb3177702e7a506e203d61 3.13 |
Sorry, something went wrong.
|
GH-148469 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
…`__delattr__` in frozen dataclasses with slots (pythonGH-144021) (cherry picked from commit 8a398bf) Co-authored-by: Sviataslau <35541026+Prometheus3375@users.noreply.github.com>
… `__delattr__` in frozen dataclasses with slots (GH-144021) (#148469) gh-105936: Properly update closure cells for `__setattr__` and `__delattr__` in frozen dataclasses with slots (GH-144021) (cherry picked from commit 8a398bf) Co-authored-by: Prometheus3375 <prometheus3375@gmail.com> Co-authored-by: Sviataslau <35541026+Prometheus3375@users.noreply.github.com>
…_` and `__delattr__` in frozen dataclasses with slots (pythonGH-144021) pythongh-105936: Properly update closure cells for `__setattr__` and `__delattr__` in frozen dataclasses with slots (pythonGH-144021) (cherry picked from commit 8a398bf) The cherry-pick required additional changes beyond the original commit because 3.13 lacks the `__class__` closure cell fixup machinery that was added in 3.14 by pythonGH-124455 (pythongh-90562). Specifically: - Backported `_update_func_cell_for__class__()` helper function and the closure fixup loop in `_add_slots()` from pythonGH-124455. Without these, renaming the closure variable from `cls` to `__class__` has no effect because nothing updates the cell when the class is recreated with slots. - Changed `_add_slots()` to use `newcls` instead of reusing `cls` for the recreated class, so both old and new class references are available for the fixup loop. - Replaced `assertNotHasAttr` with `assertFalse(hasattr(...))` in tests (assertNotHasAttr was added in 3.14). - Dropped `test_original_class_is_gced` additions (that test does not exist on 3.13; it was added by pythonGH-137047 for pythongh-135228 which was not backported to 3.13). Co-authored-by: Prometheus3375 <prometheus3375@gmail.com> Co-authored-by: Sviataslau <35541026+Prometheus3375@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
GH-148476 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
…__` and `__delattr__` in frozen dataclasses with slots (pythonGH-144021)" This reverts commit 8a398bf.
…`__delattr__` in frozen dataclasses with slots (pythonGH-144021)
…_delattr__ in frozen dataclasses with slots (GH-144021) (GH-148476) gh-105936: Properly update closure cells for `__setattr__` and `__delattr__` in frozen dataclasses with slots (GH-144021) (cherry picked from commit 8a398bf) The cherry-pick required additional changes beyond the original commit because 3.13 lacks the `__class__` closure cell fixup machinery that was added in 3.14 by GH-124455 (gh-90562). Specifically: - Backported `_update_func_cell_for__class__()` helper function and the closure fixup loop in `_add_slots()` from GH-124455. Without these, renaming the closure variable from `cls` to `__class__` has no effect because nothing updates the cell when the class is recreated with slots. - Changed `_add_slots()` to use `newcls` instead of reusing `cls` for the recreated class, so both old and new class references are available for the fixup loop. - Replaced `assertNotHasAttr` with `assertFalse(hasattr(...))` in tests (assertNotHasAttr was added in 3.14). - Dropped `test_original_class_is_gced` additions (that test does not exist on 3.13; it was added by GH-137047 for gh-135228 which was not backported to 3.13). gh-148947: dataclasses: fix error on empty __class__ cell (GH-148948) Also add a test demonstrating the need for the existing "is oldcls" check. (cherry picked from commit 6d7bbee) --------- Co-authored-by: Prometheus3375 <prometheus3375@gmail.com> Co-authored-by: Sviataslau <35541026+Prometheus3375@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
| Back | FazBrowse Home | New Git URL |
Specifying frozen=True for a dataclass adds methods __setattr__ and __detattr__ to it. These methods reference the class via closure. If slots=True is 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 via cls; hence, they are still referencing the old class instead of the new one. This PR fixes this issue.
Additional 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.