Skip to content

Commit d716214

Browse files
committed
Fix logic for determining "mandatory" and data representation
1 parent 8c81320 commit d716214

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pydifact/syntax/common.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,18 @@ def validate(self, mandatory: bool = None, repeat: int = None) -> None:
263263
for index, value in enumerate(self.elements):
264264
current_schema = self.schema[index]
265265
TemplateClass = current_schema[0]
266+
# If data structure representation is not overridden, use
267+
# the default value of the DataElement class.
268+
data_struct_representation = getattr(TemplateClass, "repr", None)
266269
if len(current_schema) > 1:
267-
if not mandatory:
270+
if mandatory is None:
268271
# If mandatory is not set, use the default value from the schema,
269272
# or assume True if not set.
270-
mandatory = (
271-
(current_schema[1] == "M") if len(current_schema) > 1 else True
272-
)
273-
# If data structure representation is not overridden, use
274-
# the default value from the schema
273+
mandatory = current_schema[1] == M
275274
elif len(current_schema) > 2:
275+
# override representation if set in schema
276276
data_struct_representation = current_schema[2]
277-
else:
278-
data_struct_representation = getattr(TemplateClass, "repr", None)
277+
279278
if mandatory:
280279
# FIXME: even if not mandatory, but present, validation should be done.
281280
TemplateClass(value).validate(

0 commit comments

Comments
 (0)