summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-05-26 08:22:50 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-05-26 08:24:38 +0200
commitdf254206dbb8f8da866ff63e1afa40528efc6ce9 (patch)
treee33635d95209babc975aac6c8bfae6b8d9e86146
parent1bb0aa98dd91152dee8421e9bccc91e1958bc574 (diff)
downloadastroid-git-df254206dbb8f8da866ff63e1afa40528efc6ce9.tar.gz
Protect against passing lookup_class to non-class proxied objects
In some cases the _proxied object points to another Instance, not to the Class of an Instance node (usually this happens with enum and with our hardcoded inference support for this library). Instead of getting a TypeError, we check before if the _proxied matches what we expect. Found by #2080
-rw-r--r--astroid/bases.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/astroid/bases.py b/astroid/bases.py
index 3b6a248a..873b8972 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -170,10 +170,13 @@ class BaseInstance(Proxy):
for stmt in _infer_stmts(self._wrap_attr(get_attr, context),
context, frame=self):
yield stmt
- except exceptions.AttributeInferenceError:
+ except exceptions.AttributeInferenceError as error:
try:
# fallback to class.igetattr since it has some logic to handle
# descriptors
+ # But only if the _proxied is the Class.
+ if self._proxied.__class__.__name__ != 'ClassDef':
+ util.reraise(exceptions.InferenceError(**vars(error)))
attrs = self._proxied.igetattr(name, context, class_context=False)
for stmt in self._wrap_attr(attrs, context):
yield stmt