Skip to content

Commit a857713

Browse files
authored
Fix classvars not being picked up in the modelDescription (#239)
1 parent 65295a9 commit a857713

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

pythonfmu/fmi2slave.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,11 @@ def to_xml(self, model_options: Dict[str, str] = dict()) -> Element:
7575
generationDateAndTime=date_str,
7676
variableNamingConvention="structured"
7777
)
78-
if self.description is not None:
79-
attrib["description"] = self.description
80-
if self.author is not None:
81-
attrib["author"] = self.author
82-
if self.license is not None:
83-
attrib["license"] = self.license
84-
if self.version is not None:
85-
attrib["version"] = self.version
86-
if self.copyright is not None:
87-
attrib["copyright"] = self.copyright
78+
# use getattr to allow either class or instance attributes to be used
79+
for attr in ["description", "author", "license", "version", "copyright"]:
80+
value = getattr(self.__class__, attr, getattr(self, attr, None))
81+
if value is not None:
82+
attrib[attr] = value
8883

8984
root = Element("fmiModelDescription", attrib)
9085

0 commit comments

Comments
 (0)