Skip to content

Commit

Permalink
Memoize
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 4, 2023
1 parent ca36488 commit a85e95c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/stratis_cli/_actions/_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class Purpose(Enum):


_LOOKUP = {
"Manager": (Purpose.INVOKE, MANAGER_INTERFACE),
"ObjectManager": (Purpose.INVOKE, "org.freedesktop.DBus.ObjectManager"),
"Report": (Purpose.INVOKE, REPORT_INTERFACE),
"Manager": (Purpose.INVOKE, MANAGER_INTERFACE, None),
"ObjectManager": (Purpose.INVOKE, "org.freedesktop.DBus.ObjectManager", None),
"Report": (Purpose.INVOKE, REPORT_INTERFACE, None),
}


Expand Down Expand Up @@ -82,7 +82,10 @@ def make_dyn_class(name):
:param str name: name of class to make
"""
(purpose, interface_name) = _LOOKUP[name]
(purpose, interface_name, klass) = _LOOKUP[name]

if klass is not None:
return klass

if purpose is Purpose.INVOKE:
try:
Expand All @@ -108,12 +111,12 @@ def make_dyn_class(name):
"method in the generated class definition"
) from err

return klass

except DPClientGenerationError as err: # pragma: no cover
raise StratisCliGenerationError(
f"Failed to generate class {name} needed for invoking "
"dbus-python methods"
) from err

assert False # pragma: no cover
_LOOKUP[name] = (purpose, interface_name, klass)

return klass

0 comments on commit a85e95c

Please sign in to comment.