Skip to content

Commit 8ae3f59

Browse files
authored
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 <module> doc.trade.settlement.payment_means.type_code = "30" # Virement ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Container' object has no attribute 'type_code' and no __dict__ for setting new attributes
1 parent b3f9e39 commit 8ae3f59

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drafthorse/models/container.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Container:
2+
__slots__ = ("children", "child_type")
3+
24
def __init__(self, child_type):
35
super().__init__()
46
self.children = []
@@ -26,6 +28,8 @@ def add_from_etree(self, root, strict=True):
2628

2729

2830
class SimpleContainer(Container):
31+
__slots__ = ("children", "child_type", "namespace", "tag")
32+
2933
def __init__(self, child_type, namespace, tag):
3034
super().__init__(child_type)
3135
self.namespace = namespace
@@ -51,6 +55,8 @@ def add_from_etree(self, root, strict=True):
5155

5256

5357
class CurrencyContainer(SimpleContainer):
58+
__slots__ = ("children", "child_type", "namespace", "tag")
59+
5460
def empty_element(self):
5561
from .elements import CurrencyElement
5662

@@ -65,6 +71,8 @@ def add_from_etree(self, root, strict=True):
6571

6672

6773
class IDContainer(SimpleContainer):
74+
__slots__ = ("children", "child_type", "namespace", "tag")
75+
6876
def empty_element(self):
6977
from .elements import IDElement
7078

@@ -79,6 +87,8 @@ def add_from_etree(self, root, strict=True):
7987

8088

8189
class StringContainer(SimpleContainer):
90+
__slots__ = ("children", "child_type", "namespace", "tag")
91+
8292
def empty_element(self):
8393
from .elements import StringElement
8494

0 commit comments

Comments
 (0)