Skip to content

False-positive "redefined while unused" error in stub files for constants in class scopes with the same name as module constants #10874

@AlexWaygood

Description

@AlexWaygood

Ruff currently emits a false positive F811 on the following stub file:

from x import y as y

class Foo:
    y = 42  # F811 Redefinition of unused `y` from line 1

There are really two y variables here -- one scoped within the Foo class, and one scoped within the module -- so I don't think this should trigger F811. Assignments without annotations in stub files are rare (which is why this hasn't come up before), but can be useful in enum classes. This bug came up in python/typeshed#11299.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglinterRelated to the linter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions