From 8ae3f59415723a88c11c3feca61c83bcc568e528 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Thu, 27 Nov 2025 20:54:03 +0100 Subject: [PATCH] Avoid user assigning unimplemented fields on containers. (#102) Before: doc.trade.settlement.payment_means.type_code = "30" was allowed but had no effect as payemnt_means is a container. Now it gives: Traceback (most recent call last): File "/home/mdk/src/python-drafthorse/test.py", line 54, in doc.trade.settlement.payment_means.type_code = "30" # Virement ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Container' object has no attribute 'type_code' and no __dict__ for setting new attributes --- drafthorse/models/container.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drafthorse/models/container.py b/drafthorse/models/container.py index f5ec87e..30cdfe3 100644 --- a/drafthorse/models/container.py +++ b/drafthorse/models/container.py @@ -1,4 +1,6 @@ class Container: + __slots__ = ("children", "child_type") + def __init__(self, child_type): super().__init__() self.children = [] @@ -26,6 +28,8 @@ class Container: class SimpleContainer(Container): + __slots__ = ("children", "child_type", "namespace", "tag") + def __init__(self, child_type, namespace, tag): super().__init__(child_type) self.namespace = namespace @@ -51,6 +55,8 @@ class SimpleContainer(Container): class CurrencyContainer(SimpleContainer): + __slots__ = ("children", "child_type", "namespace", "tag") + def empty_element(self): from .elements import CurrencyElement @@ -65,6 +71,8 @@ class CurrencyContainer(SimpleContainer): class IDContainer(SimpleContainer): + __slots__ = ("children", "child_type", "namespace", "tag") + def empty_element(self): from .elements import IDElement @@ -79,6 +87,8 @@ class IDContainer(SimpleContainer): class StringContainer(SimpleContainer): + __slots__ = ("children", "child_type", "namespace", "tag") + def empty_element(self): from .elements import StringElement -- 2.47.3