Skip to content

Instantly share code, notes, and snippets.

@zyga
Last active December 14, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyga/5052126 to your computer and use it in GitHub Desktop.
Save zyga/5052126 to your computer and use it in GitHub Desktop.
def shared(**kwargs):
class Shared(object):
@classmethod
def get_shared_data(cls):
return kwargs
return Shared
BaseSharedStuff = shared(username="user", password="pass")
class RemoteThingy(BaseSharedStuff):
def __new__(cls, *args, **kwargs):
self = super(RemoteThingy, cls).__new__(cls, *args, **kwargs)
self.__dict__.update(self.get_shared_data())
return self
class RemoteUser(RemoteThingy):
def __init__(self, account_id):
# no __init__ super call!
self.account_id = account_id
assert RemoteUser(12345).username == "user"
assert RemoteUser(12345).account_id == 12345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment