Skip to content

Commit

Permalink
Slot class methods no longer attempt to modify annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCEllis committed Jul 25, 2024
1 parent d1a7a99 commit b020aab
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/ducktools/classbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,6 @@ def field_slot_gatherer(cls_or_ns):
"in order to generate a slotclass"
)

# Don't want to mutate original annotations so make a copy if it exists
# Looking at the dict is a Python3.9 or earlier requirement
cls_annotations = get_ns_annotations(cls_dict)

cls_fields = {}
slot_replacement = {}

Expand All @@ -724,8 +720,6 @@ def field_slot_gatherer(cls_or_ns):

if isinstance(v, field_type):
attrib = v
if attrib.type is not NOTHING:
cls_annotations[k] = attrib.type
else:
# Plain values treated as defaults
attrib = field_type(default=v)
Expand All @@ -738,7 +732,6 @@ def field_slot_gatherer(cls_or_ns):
# In this case, slots with documentation and new annotations.
modifications = {
"__slots__": slot_replacement,
"__annotations__": cls_annotations,
}

return cls_fields, modifications
Expand Down
1 change: 0 additions & 1 deletion tests/prefab/dynamic/test_slotted_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class SlottedPrefab:
)

assert SlottedPrefab.__slots__ == {"x": None, "y": "Digits of pi"}
assert get_ns_annotations(SlottedPrefab.__dict__) == {"y": float}

ex = SlottedPrefab()

Expand Down
1 change: 0 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ class SlotsExample:

assert slots == fields
assert modifications["__slots__"] == {"a": None, "b": None, "c": "a list", "d": None}
assert modifications["__annotations__"] == {"a": int, "d": str}
assert get_ns_annotations(SlotsExample.__dict__) == {"a": int} # Original annotations dict unmodified


Expand Down

0 comments on commit b020aab

Please sign in to comment.