Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
Bug report
Bug description:
While trying to test cattrs on 3.14 I ran into this issue. Here's a simple reproducer that passes on 3.13, but doesn't on 3.14.
importgcfromdataclassesimportdataclass@dataclass(slots=True)classB:b:intgc.collect()assert [oforoingc.get_objects()ifhasattr(o,"__name__")ando.__name__=="B"]== [B]
Originally I ran into this issue with slottedattrs classes but the core problem is the same. Since slotness cannot be added to a class, dataclasses and attrs classes create a class copy with slots instead. The old class used to hang around until a GC collection happened (guess there are some reference cycles, but I never investigated thoroughly).
On 3.14, a full GC collection does not clean up the original class, causing a leak. Apart from leaking, in case of subclassing the original class will remain in the list of the parent.__subclasses__(), causing an issue.
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-135228: Break reference cycle between class and descriptors #135230
- gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible #136893
- [3.14] gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (GH-136893) #136960
- gh-135228: Create __dict__ and __weakref__ descriptors for object #136966
- [3.14] Revert "[3.14] gh-135228: When @dataclass(slots=True) replaces… #137013
- Revert "gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (#136893)" #137014
- gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (take 2) #137047
- [3.14] gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (take 2) (GH-137047) #137666
Metadata
Metadata
Assignees
Labels
Projects
Status