You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could do some clever stuff to automatically generate these classes, for example:
fromabcimportABC, abstractmethodclassBaseClass(ABC):
def__init__(self, a=1):
self.a=1@abstractmethoddefto_override(self):
passclassWithInheritedMethod:
defto_override(self):
print("Created a class called: "+self.__class__.__name__)
name="CreatedClass"globals()[name] =type(name, (WithInheritedMethod, BaseClass), {})
CreatedClass().to_override() # prints "Created a class called: CreatedClass"
We could apply a similar tactic to ToolVersions, for example to create a fully functional tool definition for Gatk4ApplyBqsr for each version of GATK, we could use:
versions= [Gatk_4_0_12, Gatk_4_1_2_0, Gatk_4_1_3_0, Gatk_4_1_4_0]
names= []
forvinversions:
# prepare the class name (NB: this is different to what we've used in the past)name=f"{Gatk4ApplyBqsrBase.tool(None)}_{v.__name__[5:]}"globals()[name] =type(name, (v, Gatk4ApplyBqsrBase, object), {})
names.append(name)
# This overrides the exports and makes sure ONLY the created classes are exported__all__=names
Caveats
It does bring intellisense, pycharm / vscode can't determine that the import actually exists (red squiggly line):
The text was updated successfully, but these errors were encountered:
Python can dynamically generate classes 😱
We could do some clever stuff to automatically generate these classes, for example:
We could apply a similar tactic to ToolVersions, for example to create a fully functional tool definition for Gatk4ApplyBqsr for each version of GATK, we could use:
Caveats
It does bring intellisense, pycharm / vscode can't determine that the import actually exists (red squiggly line):
The text was updated successfully, but these errors were encountered: