Created
May 5, 2021 03:33
-
-
Save zbentley/f76768b93363dc1618ddcedec002a160 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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