Skip to content

Instantly share code, notes, and snippets.

@ooliver1
Created October 15, 2023 17:22
Show Gist options
  • Save ooliver1/beb61378b38169a746f99414955a658d to your computer and use it in GitHub Desktop.
Save ooliver1/beb61378b38169a746f99414955a658d to your computer and use it in GitHub Desktop.
Here is your singleton implementation
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