Skip to content

Commit

Permalink
PWMProbes: Fix Singleton to attach it to the specific cls
Browse files Browse the repository at this point in the history
Previously, the hasattr call would use MRO to find _instance on the
parent so if the parent were instantiated before the child, the child
would reuse the parent's instance.

IBM#38
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
  • Loading branch information
gabe-l-hart committed Jan 23, 2024
1 parent c8b3785 commit cba9e1f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion oper8/watch_manager/python_watch_manager/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ def __call__(cls, *args, **kwargs):
if getattr(cls, "_disable_singleton", False):
return type.__call__(cls, *args, **kwargs)

if not hasattr(cls, "_instance"):
# The _instance is attached to the class itself without looking upwards
# into any parent classes
if "_instance" not in cls.__dict__:
cls._instance = type.__call__(cls, *args, **kwargs)
return cls._instance

Expand Down

0 comments on commit cba9e1f

Please sign in to comment.