Skip to content

Instantly share code, notes, and snippets.

@pritul2
Created October 8, 2022 07:31
Show Gist options
  • Save pritul2/0a653f8c6bbdc704ccce301bfc473c34 to your computer and use it in GitHub Desktop.
Save pritul2/0a653f8c6bbdc704ccce301bfc473c34 to your computer and use it in GitHub Desktop.
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