summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-08-22 10:32:21 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-08-22 10:32:21 +0200
commit1f0eff526dcc3dea0af68288c719d23767bd2581 (patch)
tree61f2d2af3ed428ba3bd8f783543321fe50101566 /astroid
parent3f0fdc5dcad43fb7a913856439848f6042c007f6 (diff)
downloadastroid-git-1f0eff526dcc3dea0af68288c719d23767bd2581.tar.gz
Filter out ``Uninferable`` when inferring the call result result of a class with an uninferable ``__call__`` method.
Close PyCQA/pylint#2434
Diffstat (limited to 'astroid')
-rw-r--r--astroid/scoped_nodes.py6
-rw-r--r--astroid/tests/unittest_scoped_nodes.py13
2 files changed, 15 insertions, 4 deletions
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 92132a13..6b440f81 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -2063,11 +2063,9 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG,
dunder_call = next(metaclass.igetattr("__call__", context))
except exceptions.AttributeInferenceError:
pass
- if (dunder_call is not None and
- dunder_call.qname() != "builtins.type.__call__"):
+ if dunder_call and dunder_call.qname() != "builtins.type.__call__":
context = contextmod.bind_context_to_node(context, self)
- yield from dunder_call.infer_call_result(
- caller, context)
+ yield from dunder_call.infer_call_result(caller, context)
else:
# Call type.__call__ if not set metaclass
# (since type is the default metaclass)
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index 85a6256d..33f151cf 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -1799,5 +1799,18 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase):
self.assertEqual([x.arg for x in cls.keywords], ['foo', 'bar'])
+def test_metaclass_cannot_infer_call_yields_an_instance():
+ node = builder.extract_node('''
+ from undefined import Undefined
+ class Meta(type):
+ __call__ = Undefined
+ class A(metaclass=Meta):
+ pass
+ A()
+ ''')
+ inferred = next(node.infer())
+ assert isinstance(inferred, Instance)
+
+
if __name__ == '__main__':
unittest.main()