diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2023-03-11 21:52:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 21:52:06 +0100 |
commit | 575319bb87de73114203c5a49edd3ae18aace8c7 (patch) | |
tree | 7c5575bd368782df1f60e568c1b13053a1963475 /pylint/checkers | |
parent | 8c3652a6a4c97d0ed0e92484d4ce15e669bd69cf (diff) | |
download | pylint-git-575319bb87de73114203c5a49edd3ae18aace8c7.tar.gz |
Fix a crash when `TYPE_CHECKING` is used without importing it (#8435) (#8436)
(cherry picked from commit 4c56ba82d7aac50b1ea34e929833c91418e1d117)
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Diffstat (limited to 'pylint/checkers')
-rw-r--r-- | pylint/checkers/utils.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 0cee91f17..c68f88388 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -1970,7 +1970,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" |