Skip to content

Commit 19175d9

Browse files
Use sys._clear_type_descriptors() on 3.14 to break slot reference cycle (#1459)
* Use sys._clear_type_descriptors() on 3.14 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * No more deproxying --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 616adf5 commit 19175d9

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/attr/_make.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
PY_3_10_PLUS,
2525
PY_3_11_PLUS,
2626
PY_3_13_PLUS,
27-
PY_3_14_PLUS,
2827
_AnnotationExtractor,
2928
_get_annotations,
3029
get_generic_base,
@@ -629,17 +628,6 @@ def evolve(*args, **changes):
629628
return cls(**changes)
630629

631630

632-
# Hack to the get the underlying dict out of a mappingproxy
633-
# Use it with: cls.__dict__ | _deproxier
634-
# See: https://github.com/python/cpython/pull/136893
635-
class _Deproxier:
636-
def __ror__(self, other):
637-
return other
638-
639-
640-
_deproxier = _Deproxier()
641-
642-
643631
class _ClassBuilder:
644632
"""
645633
Iteratively build *one* class.
@@ -869,19 +857,9 @@ def _create_slots_class(self):
869857
if k not in (*tuple(self._attr_names), "__dict__", "__weakref__")
870858
}
871859

872-
if PY_3_14_PLUS:
873-
# Clean up old dict to avoid leaks.
874-
old_cls_dict = self._cls.__dict__ | _deproxier
875-
old_cls_dict.pop("__dict__", None)
876-
if "__weakref__" in self._cls.__dict__:
877-
del self._cls.__weakref__
878-
879-
# Manually bump internal version tag.
880-
try:
881-
self._cls.__abstractmethods__ = self._cls.__abstractmethods__
882-
except AttributeError:
883-
self._cls.__abstractmethods__ = frozenset({"__init__"})
884-
del self._cls.__abstractmethods__
860+
# 3.14.0rc2+
861+
if hasattr(sys, "_clear_type_descriptors"):
862+
sys._clear_type_descriptors(self._cls)
885863

886864
# If our class doesn't have its own implementation of __setattr__
887865
# (either from the user or by us), check the bases, if one of them has

0 commit comments

Comments
 (0)