summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-10-03 14:08:49 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2015-10-03 14:08:49 +0300
commit933bad8f80b564bdff4e4450ed1f412d22ef8206 (patch)
tree671716092b50bfcb5bf0a3622b7c270a1a3a7dd0
parent211f96f28c1300de1a89b67b527b1a7b499dcc0f (diff)
downloadastroid-933bad8f80b564bdff4e4450ed1f412d22ef8206.tar.gz
Fix a crash which occurred when inferring unary operands which yielded objects which weren't callable.
-rw-r--r--astroid/inference.py2
-rw-r--r--astroid/tests/unittest_inference.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/astroid/inference.py b/astroid/inference.py
index 3f7ab5c..f7ab2be 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -373,6 +373,8 @@ def _infer_unaryop(self, context=None):
try:
meth = operand.getattr(meth, context=context)[0]
inferred = next(meth.infer(context=context))
+ if inferred is util.YES or not inferred.callable():
+ continue
call_results = inferred.infer_call_result(self, context=context)
result = next(call_results, None)
if result is None:
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index 841d9ff..fbd97e2 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -2016,6 +2016,14 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
inferred = next(bad_node.infer())
self.assertEqual(inferred, util.YES)
+ def test_unary_op_instance_method_not_callable(self):
+ ast_node = test_utils.extract_node('''
+ class A:
+ __pos__ = (i for i in range(10))
+ +A() #@
+ ''')
+ self.assertRaises(InferenceError, next, ast_node.infer())
+
def test_binary_op_type_errors(self):
ast_nodes = test_utils.extract_node('''
import collections