Created
October 15, 2023 17:22
-
-
Save ooliver1/beb61378b38169a746f99414955a658d to your computer and use it in GitHub Desktop.
Here is your singleton implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Singleton = type("Singleton", (), {"instance": None, "__new__": lambda cls: (cls.instance if cls.instance else (self := super(Singleton, cls).__new__(cls), setattr(cls, "instance", self))[0])}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment