From b020aab46e343ea515c2fd86429da199c74712a1 Mon Sep 17 00:00:00 2001 From: David C Ellis Date: Thu, 25 Jul 2024 13:58:50 +0100 Subject: [PATCH] Slot class methods no longer attempt to modify annotations --- src/ducktools/classbuilder/__init__.py | 7 ------- tests/prefab/dynamic/test_slotted_class.py | 1 - tests/test_core.py | 1 - 3 files changed, 9 deletions(-) diff --git a/src/ducktools/classbuilder/__init__.py b/src/ducktools/classbuilder/__init__.py index 933a8fa..51d70bf 100644 --- a/src/ducktools/classbuilder/__init__.py +++ b/src/ducktools/classbuilder/__init__.py @@ -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 = {} @@ -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) @@ -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 diff --git a/tests/prefab/dynamic/test_slotted_class.py b/tests/prefab/dynamic/test_slotted_class.py index 0c8ebf6..e741b0a 100644 --- a/tests/prefab/dynamic/test_slotted_class.py +++ b/tests/prefab/dynamic/test_slotted_class.py @@ -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() diff --git a/tests/test_core.py b/tests/test_core.py index 46a1a63..dacd124 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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