getattr() / __getattribute__ / __getattr__ implementation

This commit is contained in:
David Halter
2012-09-13 02:09:50 +02:00
parent dd8d1217c6
commit 1a4de1bc68
3 changed files with 113 additions and 9 deletions

View File

@@ -464,3 +464,44 @@ a[1]
WithoutMethod.blub(WithoutMethod())
#? str()
WithoutMethod.blub(B())
# -----------------
# __getattr__ / getattr() / __getattribute__
# -----------------
#? str().upper
getattr(str(), 'upper')
#? str.upper
getattr(str, 'upper')
# some strange getattr calls
#?
getattr(str, 1)
#?
getattr()
#?
getattr(str)
#?
getattr(getattr, 1)
class Base():
def ret(self, b):
return b
class Wrapper():
def __init__(self, obj):
self.obj = obj
def __getattr__(self, name):
return getattr(self.obj, name)
class Wrapper2():
def __getattribute__(self, name):
return getattr(Base(), name)
#? int()
Wrapper(Base()).ret(3)
#? int()
Wrapper2(Base()).ret(3)