Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_type_checking_block can crash if you haven't imported TYPE_CHECKING #8434

Closed
jacobtylerwalls opened this issue Mar 11, 2023 · 0 comments · Fixed by #8435, #8521 or #9093
Closed

in_type_checking_block can crash if you haven't imported TYPE_CHECKING #8434

jacobtylerwalls opened this issue Mar 11, 2023 · 0 comments · Fixed by #8435, #8521 or #9093
Assignees
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Mar 11, 2023

Bug description

if TYPE_CHECKING:  # don't import this!
    pass
else:
    import math

Configuration

No response

Command used

pylint a.py

Pylint output

File "/Users/.../pylint/pylint/utils/ast_walker.py", line 96, in walk
    callback(astroid)
  File "/Users/.../pylint/pylint/checkers/variables.py", line 1329, in leave_module
    self._check_imports(not_consumed)
  File "/Users/.../pylint/pylint/checkers/variables.py", line 3071, in _check_imports
    if not in_type_checking_block(stmt):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../pylint/pylint/checkers/utils.py", line 1921, in in_type_checking_block
    maybe_import_from = ancestor.test.lookup(ancestor.test.name)[1][0]
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

Expected behavior

************* Module a
a.py:1:3: E0602: Undefined variable 'TYPE_CHECKING' (undefined-variable)
a.py:4:4: W0611: Unused import math (unused-import)

Pylint version

pylint 3.0.0a6
astroid 2.16.0dev0
Python 3.11.0

OS / Environment

No response

Additional dependencies

No response

@jacobtylerwalls jacobtylerwalls added Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Mar 11, 2023
@jacobtylerwalls jacobtylerwalls added this to the 2.17.1 milestone Mar 11, 2023
@jacobtylerwalls jacobtylerwalls self-assigned this Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
1 participant