Add __getattr__ checks with proper inheritance.

This commit is contained in:
Dave Halter
2014-06-26 12:56:01 +02:00
parent a936cea987
commit 4238538df4
2 changed files with 28 additions and 3 deletions

View File

@@ -318,9 +318,10 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
return result + list(type_cls.get_defined_names())
def get_subscope_by_name(self, name):
for sub in reversed(self.subscopes):
if sub.name.get_code() == name:
return sub
for s in [self] + self.get_super_classes():
for sub in reversed(s.subscopes):
if sub.name.get_code() == name:
return sub
raise KeyError("Couldn't find subscope.")
def is_callable(self):

View File

@@ -0,0 +1,24 @@
"""
Jedi issues warnings for possible errors if ``__getattr__``,
``__getattribute__`` or ``setattr`` are used.
"""
class Cls():
def __getattr__(self, name):
return getattr(str, name)
Cls().upper
#! 6 warning attribute-error
Cls().undefined
class Inherited(Cls):
pass
Inherited().upper
#! 12 warning attribute-error
Inherited().undefined