mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Add __getattr__ checks with proper inheritance.
This commit is contained in:
@@ -318,9 +318,10 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
|||||||
return result + list(type_cls.get_defined_names())
|
return result + list(type_cls.get_defined_names())
|
||||||
|
|
||||||
def get_subscope_by_name(self, name):
|
def get_subscope_by_name(self, name):
|
||||||
for sub in reversed(self.subscopes):
|
for s in [self] + self.get_super_classes():
|
||||||
if sub.name.get_code() == name:
|
for sub in reversed(s.subscopes):
|
||||||
return sub
|
if sub.name.get_code() == name:
|
||||||
|
return sub
|
||||||
raise KeyError("Couldn't find subscope.")
|
raise KeyError("Couldn't find subscope.")
|
||||||
|
|
||||||
def is_callable(self):
|
def is_callable(self):
|
||||||
|
|||||||
24
test/static_analysis/attribute_warnings.py
Normal file
24
test/static_analysis/attribute_warnings.py
Normal 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
|
||||||
Reference in New Issue
Block a user