Skip to content

Commit 0018224

Browse files
committed
Handle python positional arguments in case of derived fields more explicitly
1 parent 334d867 commit 0018224

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/ifcopenshell-python/ifcopenshell/entity_instance.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,33 @@ def __getitem__(self, key):
108108
return entity_instance.wrap_value(self.wrapped_data.get_argument(key))
109109

110110
def __setitem__(self, idx, value):
111+
attr_type = real_attr_type = self.attribute_type(idx).title().replace(' ', '')
112+
real_attr_type = real_attr_type.replace('Derived', 'None')
113+
attr_type = attr_type.replace('Binary', 'String')
114+
attr_type = attr_type.replace('Enumeration', 'String')
115+
111116
if value is None:
112-
self.wrapped_data.setArgumentAsNull(idx)
117+
if attr_type != "Derived":
118+
self.wrapped_data.setArgumentAsNull(idx)
113119
else:
114-
attr_type = real_attr_type = self.attribute_type(idx).title().replace(' ', '')
115-
attr_type = attr_type.replace('Binary', 'String')
116-
attr_type = attr_type.replace('Enumeration', 'String')
117-
try:
118-
if isinstance(value, unicode):
119-
value = value.encode("utf-8")
120-
except BaseException:
121-
pass
122-
try:
123-
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
124-
except BaseException:
120+
valid = attr_type != "Derived"
121+
if valid:
122+
try:
123+
if isinstance(value, unicode):
124+
value = value.encode("utf-8")
125+
except BaseException:
126+
pass
127+
128+
try:
129+
if attr_type != "Derived":
130+
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
131+
except BaseException as e:
132+
valid = False
133+
134+
if not valid:
125135
raise ValueError("Expected %s for attribute %s.%s, got %r" % (
126136
real_attr_type, self.is_a(), self.attribute_name(idx), value))
137+
127138
return value
128139

129140
def __len__(self):

0 commit comments

Comments
 (0)