Skip to content
New issue

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

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

Already on GitHub? # to your account

False positive unused-variable for TYPE_CHECKING imports #8696

Closed
zenlyj opened this issue May 17, 2023 · 0 comments · Fixed by #8713
Closed

False positive unused-variable for TYPE_CHECKING imports #8696

zenlyj opened this issue May 17, 2023 · 0 comments · Fixed by #8713
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@zenlyj
Copy link
Contributor

zenlyj commented May 17, 2023

Bug description

When allow-global-unused-variables is set to false in the configuration, the unused-variable warning is raised for imports made under TYPE_CHECKING guard clauses. This behavior seems inconsistent with unused-import, which is not raised for such cases.

# test.py
# pylint: disable=missing-module-docstring

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import math  # [unused-variable]

Configuration

[tool.pylint.variables]
allow-global-unused-variables=false

Command used

pylint test.py

Pylint output

************* Module test
test.py:6:4: W0612: Unused variable 'math' (unused-variable)

Expected behavior

No warnings raised.

Pylint version

pylint 3.0.0b1
astroid 3.0.0a2
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0]

OS / Environment

WSL2 Ubuntu 20.04 LTS

Additional dependencies

No response

@zenlyj zenlyj added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 17, 2023
@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 17, 2023
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue May 23, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration.

Closes pylint-dev#8696
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue May 23, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration.

Closes pylint-dev#8696
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue May 31, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration.

Closes pylint-dev#8696
@jacobtylerwalls jacobtylerwalls modified the milestones: 3.0.0a7, 2.17.5 Jun 6, 2023
Pierre-Sassoulas pushed a commit that referenced this issue Jun 6, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration. (#8713)

Closes #8696
github-actions bot pushed a commit that referenced this issue Jun 6, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration. (#8713)

Closes #8696

(cherry picked from commit e5584d5)
Pierre-Sassoulas pushed a commit that referenced this issue Jun 6, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration. (#8713)

Closes #8696

(cherry picked from commit e5584d5)
Pierre-Sassoulas pushed a commit that referenced this issue Jun 6, 2023
…in a ``if TYPE_CHECKING:`` block and ``allow-global-unused-variables`` is set to ``no`` in the configuration. (#8713) (#8744)

Closes #8696

(cherry picked from commit e5584d5)

Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants