Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions UM/Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,21 @@ def wrapper(instance, *args, **kwargs):
return result.copy()
return copy.copy(result)
return wrapper

def singleton(cls):
"""
Function decorator that marks a class as being a Singleton, so that it gets a getInstance method.
note: I couldn't find a way to make typing-based PyCharm code-completion work with this properly.
If there is a way, please advise :)
"""

cls.__instance = None

def getInstance(cls_):
if cls_.__instance is None:
cls_.__instance = cls_()
return cls_.__instance

cls.getInstance = classmethod(getInstance)

return cls
Loading