about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/openpyxl/descriptors/slots.py
diff options
context:
space:
mode:
Diffstat (limited to '.venv/lib/python3.12/site-packages/openpyxl/descriptors/slots.py')
-rw-r--r--.venv/lib/python3.12/site-packages/openpyxl/descriptors/slots.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/openpyxl/descriptors/slots.py b/.venv/lib/python3.12/site-packages/openpyxl/descriptors/slots.py
new file mode 100644
index 00000000..cadc1ef3
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/openpyxl/descriptors/slots.py
@@ -0,0 +1,18 @@
+# Metaclass for mixing slots and descriptors
+# From "Programming in Python 3" by Mark Summerfield Ch.8 p. 383
+
+class AutoSlotProperties(type):
+
+    def __new__(mcl, classname, bases, dictionary):
+        slots = list(dictionary.get("__slots__", []))
+        for getter_name in [key for key in dictionary if key.startswith("get_")]:
+            name = getter_name
+            slots.append("__" + name)
+            getter = dictionary.pop(getter_name)
+            setter = dictionary.get(setter_name, None)
+            if (setter is not None
+                and isinstance(setter, collections.Callable)):
+                del dictionary[setter_name]
+            dictionary[name] = property(getter. setter)
+            dictionary["__slots__"] = tuple(slots)
+            return super().__new__(mcl, classname, bases, dictionary)