-
Notifications
You must be signed in to change notification settings - Fork 3
Description
The documentation examples suggest to import pythonfmu3 as, for example:
from pythonfmu3 import Fmi3Causality, Fmi3Slave, Boolean, Int32, Float64, String
However, one may wish to import like this:
import pythonfmu3 as pyfmu3
Then, later in the code, do something like this:
class MyFMU(pyfmu3.Fmi3Slave):
...
However, when compiling the FMU, this will fail with the following error message:
File "E:\Pegasus\sensors\fmu_venv\lib\site-packages\pythonfmu3\builder.py", line 27, in get_class_name
return re.search(r'class (\w+)\(\s*Fmi3Slave\s*\)\s*:', data).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
So, it appears that the pythonFMU3 code relies on the import style used in the documentation examples, because it searches for class declarations that look like this:
class PythonSlave(Fmi3Slave):
....
and not like the MyFMU case above.
Users should be able to import the code either way.
Incidentally, is searching for regular expressions in the code the best way to find classes that extend Fmi3Slave? Would it not be better to instantiate classes, test if they are an instance of Fmi3Slave (which will be True for all subclasses), then get the name via reflection? e.g. type(subclass_instance).__name__