Skip to content

Commit 6a285f9

Browse files
Revert "gh-135228: When @DataClass(slots=True) replaces a dataclass, make the original class collectible (#136893)" (#137014)
This reverts commit 46cbdf9.
1 parent 38b936c commit 6a285f9

File tree

3 files changed

+0
-54
lines changed

3 files changed

+0
-54
lines changed

Lib/dataclasses.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,13 +1338,6 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
13381338
or _update_func_cell_for__class__(member.fdel, cls, newcls)):
13391339
break
13401340

1341-
# gh-135228: Make sure the original class can be garbage collected.
1342-
# Bypass mapping proxy to allow __dict__ to be removed
1343-
old_cls_dict = cls.__dict__ | _deproxier
1344-
old_cls_dict.pop('__dict__', None)
1345-
if "__weakref__" in cls.__dict__:
1346-
del cls.__weakref__
1347-
13481341
return newcls
13491342

13501343

@@ -1739,11 +1732,3 @@ def _replace(self, /, **changes):
17391732
# changes that aren't fields, this will correctly raise a
17401733
# TypeError.
17411734
return self.__class__(**changes)
1742-
1743-
1744-
# Hack to the get the underlying dict out of a mappingproxy
1745-
# Use it with: cls.__dict__ | _deproxier
1746-
class _Deproxier:
1747-
def __ror__(self, other):
1748-
return other
1749-
_deproxier = _Deproxier()

Lib/test/test_dataclasses/__init__.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,41 +3804,6 @@ class WithCorrectSuper(CorrectSuper):
38043804
# that we create internally.
38053805
self.assertEqual(CorrectSuper.args, ["default", "default"])
38063806

3807-
def test_original_class_is_gced(self):
3808-
# gh-135228: Make sure when we replace the class with slots=True, the original class
3809-
# gets garbage collected.
3810-
def make_simple():
3811-
@dataclass(slots=True)
3812-
class SlotsTest:
3813-
pass
3814-
3815-
return SlotsTest
3816-
3817-
def make_with_annotations():
3818-
@dataclass(slots=True)
3819-
class SlotsTest:
3820-
x: int
3821-
3822-
return SlotsTest
3823-
3824-
def make_with_annotations_and_method():
3825-
@dataclass(slots=True)
3826-
class SlotsTest:
3827-
x: int
3828-
3829-
def method(self) -> int:
3830-
return self.x
3831-
3832-
return SlotsTest
3833-
3834-
for make in (make_simple, make_with_annotations, make_with_annotations_and_method):
3835-
with self.subTest(make=make):
3836-
C = make()
3837-
support.gc_collect()
3838-
candidates = [cls for cls in object.__subclasses__() if cls.__name__ == 'SlotsTest'
3839-
and cls.__firstlineno__ == make.__code__.co_firstlineno + 1]
3840-
self.assertEqual(candidates, [C])
3841-
38423807

38433808
class TestDescriptors(unittest.TestCase):
38443809
def test_set_name(self):

Misc/NEWS.d/next/Library/2025-07-20-16-56-55.gh-issue-135228.n_XIao.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy