Skip to content

Commit

Permalink
fix bugbear caching of class instance
Browse files Browse the repository at this point in the history
  • Loading branch information
marscher committed Dec 13, 2023
1 parent db9b96c commit da29b4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions weldx_widgets/widget_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,19 @@ def schema(self) -> str:
"""Return a schema name is used to validate input and output."""
pass

@staticmethod
@functools.lru_cache
def get_schema_path(self) -> Path:
def _get_schema_path(schema) -> Path:
"""Resolve a schema name to path."""
return get_schema_path(self.schema)
return get_schema_path(schema)

def get_schema_path(self) -> Path:
return WeldxImportExport._get_schema_path(self.schema)

def validate(self, tree):
"""Validate given tree against schema of this class."""
# should be implemented such that we can validate both input and output.
pass
return

@abc.abstractmethod
def from_tree(self, tree: dict):
Expand Down
5 changes: 3 additions & 2 deletions weldx_widgets/widget_gmaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,17 @@ def __init__(self, process_type="spray"):
def _create_process_widgets(self, change):
new = change["new"]
arg = self.translate[new]
box = self._cached_process_widgets(arg)
box = WidgetGMAW._cached_process_widgets(arg)
self._welding_process.children = (box,)

@property
def welding_process(self) -> Union[ProcessSpray, ProcessPulsed]:
"""Return welding process widget."""
return self._welding_process.children[0]

@staticmethod
@lru_cache(None)
def _cached_process_widgets(self, process):
def _cached_process_widgets(process):
if process == "spray":
return ProcessSpray()

Expand Down

0 comments on commit da29b4a

Please sign in to comment.