summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-03-11 14:54:32 -0500
committerGitHub <noreply@github.com>2023-03-11 14:54:32 -0500
commit4c56ba82d7aac50b1ea34e929833c91418e1d117 (patch)
tree8b8d3594de027cbd970e24d9ff117f05f10ebb51 /pylint
parent74e6efcec09dff861254289465a3f06c803dbc4f (diff)
downloadpylint-git-4c56ba82d7aac50b1ea34e929833c91418e1d117.tar.gz
Fix a crash when `TYPE_CHECKING` is used without importing it (#8435)
Diffstat (limited to 'pylint')
-rw-r--r--pylint/checkers/utils.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 4fdb3ad22..325429afe 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -1918,7 +1918,10 @@ def in_type_checking_block(node: nodes.NodeNG) -> bool:
if isinstance(ancestor.test, nodes.Name):
if ancestor.test.name != "TYPE_CHECKING":
continue
- maybe_import_from = ancestor.test.lookup(ancestor.test.name)[1][0]
+ lookup_result = ancestor.test.lookup(ancestor.test.name)[1]
+ if not lookup_result:
+ return False
+ maybe_import_from = lookup_result[0]
if (
isinstance(maybe_import_from, nodes.ImportFrom)
and maybe_import_from.modname == "typing"