summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Vielsmaier <martin.vielsmaier@gmail.com>2019-05-05 10:16:07 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-05-05 10:16:07 +0200
commit7054204c688947e6c056cde27190951bfe8f63e9 (patch)
tree05ff54f74e72008bfc6997f78eac6a6757c50bd8
parentc26bd45edb74f1857471fcd134c8443058670790 (diff)
downloadpylint-git-7054204c688947e6c056cde27190951bfe8f63e9.tar.gz
Fix crash in callable check (#2901)
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--ChangeLog2
-rw-r--r--pylint/checkers/typecheck.py3
-rw-r--r--pylint/test/unittest_checker_typecheck.py16
4 files changed, 22 insertions, 1 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index ea603452b..d01b830aa 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -299,3 +299,5 @@ contributors:
* Zeb Nicholls: contributor
- Made W9011 compatible with 'of' syntax in return types
+
+* Martin Vielsmaier: contributor
diff --git a/ChangeLog b/ChangeLog
index 59b18f0ef..93192a473 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@ What's New in Pylint 2.4.0?
Release date: TBA
+* Fix crash happening when parent of called object cannot be determined
+
* Allow of in `GoogleDocstring.re_multiple_type`
* Added `subprocess-run-check` to handle subrocess.run without explicitly set `check` keyword.
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index d5981ab3b..1b96d5d26 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -1051,7 +1051,8 @@ accessed. Python regular expressions are accepted.",
if isinstance(called, astroid.Instance) and (
not has_known_bases(called)
or (
- isinstance(called.scope(), astroid.ClassDef)
+ called.parent is not None
+ and isinstance(called.scope(), astroid.ClassDef)
and "__get__" in called.locals
)
):
diff --git a/pylint/test/unittest_checker_typecheck.py b/pylint/test/unittest_checker_typecheck.py
index 7bce396c5..ba61a7d13 100644
--- a/pylint/test/unittest_checker_typecheck.py
+++ b/pylint/test/unittest_checker_typecheck.py
@@ -332,3 +332,19 @@ class TestTypeChecker(CheckerTestCase):
)
with self.assertNoMessages():
self.checker.visit_call(call)
+
+ def test_unknown_parent(self):
+ """Make sure the callable check does not crash when a node's parent
+ cannot be determined.
+ """
+ call = astroid.extract_node(
+ """
+ def get_num(n):
+ return 2 * n
+ get_num(10)()
+ """
+ )
+ with self.assertAddsMessages(
+ Message("not-callable", node=call, args="get_num(10)")
+ ):
+ self.checker.visit_call(call)