Skip to content

Commit

Permalink
Remove unnecessary __attrs_original_getattr__ from class dictionary.
Browse files Browse the repository at this point in the history
  • Loading branch information
diabolo-dan committed Nov 27, 2023
1 parent 07741dd commit bac209e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import enum
import functools
import inspect
import itertools
import linecache
import sys
import types
Expand Down Expand Up @@ -926,6 +927,9 @@ def _create_slots_class(self):
# So can't be used before this.
cached_properties = {}

# Collect methods with a `__class__` reference that are shadowed in the new class.
# To know to update them.
additional_closure_functions_to_update = []
if cached_properties:
# Add cached properties to names for slotting.
names += tuple(cached_properties.keys())
Expand All @@ -942,7 +946,7 @@ def _create_slots_class(self):

original_getattr = cd.get("__getattr__")
if original_getattr is not None:
cd["__attrs_original_getattr__"] = original_getattr
additional_closure_functions_to_update.append(original_getattr)

cd["__getattr__"] = _make_cached_property_getattr(
cached_properties, original_getattr, self._cls
Expand Down Expand Up @@ -979,7 +983,9 @@ def _create_slots_class(self):
# compiler will bake a reference to the class in the method itself
# as `method.__closure__`. Since we replace the class with a
# clone, we rewrite these references so it keeps working.
for item in cls.__dict__.values():
for item in itertools.chain(
cls.__dict__.values(), additional_closure_functions_to_update
):
if isinstance(item, (classmethod, staticmethod)):
# Class- and staticmethods hide their functions inside.
# These might need to be rewritten as well.
Expand Down

0 comments on commit bac209e

Please sign in to comment.