Created
October 8, 2022 07:31
-
-
Save pritul2/0a653f8c6bbdc704ccce301bfc473c34 to your computer and use it in GitHub Desktop.
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
class Monostate(object): | |
_shared_state = {} | |
def __new__(cls, *a, **kw): | |
obj = super(Monostate, cls).__new__(*a, **kw) | |
obj.__dict__ = _shared_state | |
return obj | |
class Foo(Monostate) pass | |
class Bar(Foo) pass | |
f = Foo() | |
b = Bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment