-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Currently, we maintain a mapping between various classnames and the actual names of the classes they point to. For example, "pin" maps to the class PinAssembly. These mappings are used in various places to determine which class to instantiate.
Suggest we replace this functionality with a function which returns the subclass by its actual name (here, PinAssembly). This would be much easier to maintain and read, as well as improving extensibility.
The function might look something like this:
def get_subclass_from_classname(classname) -> Assembly | Component:
"""Return an Assembly or Component subclass by name."""
base_classes = [Assembly, Component]
for bc in base_classes:
for sc in bc.__subclasses__():
if sc.__name__ == classname:
return subclass
raise ValueError("No such class.")Note with this change, we would then use the proper class name in the json files "class": "PinAssembly" instead of "class": "pin". This would be a breaking change, but should lead to a simplier interface in the end.
Note that this should also pick up any user-defined subclasses which would also be in scope. See issue #66.
I suggest we only retain the current lower case classnames for use in the identifiers. See issue #75. (We could use the CamelCase classnames without issue, but the consideration for identifiers should be more about how assembly and component names should appear in the resulting exported files.)