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

False positive used-before-assignment when TYPE_CHECKING is used with if/elif/else blocks #7574

Closed
yilei opened this issue Oct 4, 2022 · 0 comments · Fixed by #8071
Closed
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check Control flow Requires control flow understanding 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

@yilei
Copy link
Contributor

yilei commented Oct 4, 2022

Bug description

Example

# pylint: disable=import-error,missing-function-docstring,invalid-name
"""."""

from typing import TYPE_CHECKING, Optional
from package import runtime


if TYPE_CHECKING:
    from package import module
elif runtime.is_local:
    from package import module
else:
    module = None


def diagnose() -> Optional[module.Result]:
    if module is not None:
        return module.diagnose_result()
    return None

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:16:27: E0601: Using variable 'module' before assignment (used-before-assignment)

------------------------------------------------------------------
Your code has been rated at 5.45/10 (previous run: 5.45/10, +0.00)

Expected behavior

No used-before-assignment should be raised.

Pylint version

pylint 2.15.3
astroid 2.12.10
Python 3.8.10 (default, Jul  6 2022, 10:42:32)
[Clang 13.0.0 (clang-1300.0.29.30)]

OS / Environment

No response

Additional dependencies

No response

@yilei yilei added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 4, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Control flow Requires control flow understanding False Positive 🦟 A message is emitted but nothing is wrong with the code Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 5, 2022
@jacobtylerwalls jacobtylerwalls added the C: used-before-assignment Issues related to 'used-before-assignment' check label Oct 14, 2022
@jacobtylerwalls jacobtylerwalls self-assigned this Oct 14, 2022
@jacobtylerwalls jacobtylerwalls added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Oct 14, 2022
@jacobtylerwalls jacobtylerwalls modified the milestone: 2.15.5 Oct 14, 2022
@jacobtylerwalls jacobtylerwalls removed their assignment Oct 21, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.2 milestone Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check Control flow Requires control flow understanding 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.

3 participants