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 for type annotations in inner functions #9391

Closed
clo-vis opened this issue Jan 26, 2024 · 0 comments · Fixed by #10275
Closed

False positive used-before-assignment for type annotations in inner functions #9391

clo-vis opened this issue Jan 26, 2024 · 0 comments · Fixed by #10275
Assignees
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

@clo-vis
Copy link

clo-vis commented Jan 26, 2024

Bug description

from typing import NamedTuple


def function() -> None:
    def new_obj() -> Foo:
        return Foo(1)

    print(new_obj())


class Foo(NamedTuple):
    field: int


function()

Configuration

No response

Command used

pylint src\test.py

Pylint output

************* Module src.test
src\test.py:5:21: E0601: Using variable 'Foo' before assignment (used-before-assignment)

Expected behavior

No errors. The "variable" Foo should be tagged as used-before-assigned only if the function were defined at module level.

As a side note, pylint doesn't output any errors for

from typing import NamedTuple


def function() -> None:
    print(Foo())

    def new_obj() -> Foo:
        return Foo(1)

    print(new_obj())


class Foo(NamedTuple):
    field: int


function()

Pylint version

pylint 3.0.3
astroid 3.0.2
Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]

OS / Environment

Microsoft Windows [Version 10.0.19045.3930]

Additional dependencies

No response

@clo-vis clo-vis added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 26, 2024
@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 Feb 10, 2024
@jacobtylerwalls jacobtylerwalls added this to the 3.3.6 milestone Mar 13, 2025
@jacobtylerwalls jacobtylerwalls self-assigned this Mar 13, 2025
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 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