Skip to content

Instantly share code, notes, and snippets.

@zbentley
Created May 5, 2021 03:33
Show Gist options
  • Save zbentley/f76768b93363dc1618ddcedec002a160 to your computer and use it in GitHub Desktop.
Save zbentley/f76768b93363dc1618ddcedec002a160 to your computer and use it in GitHub Desktop.
class Foo(object):
def __init__(s, foo):
s.wrapped = foo
def __getattr__(s, attr):
target = attr
if attr.startswith('__') and not attr.endswith('__'):
target = '_{}{}'.format(s.wrapped.__class__.__name__, attr)
return getattr(s.wrapped, target)
class Other(object):
def __spec(s):
print(123)
def __len__(s):
return 5
inner = Other()
a = Foo(inner)
print(dir(a))
print(dir(inner))
print(a.__len__())
print(len(a)) # Wat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment