Skip to content

B024: false negative with annotated, unassigned instance variables of a class #14503

@cmp0xff

Description

@cmp0xff

This issue derives from #14455 (comment).

[copied from other issue] Meanwhile, upon checking the Python documentation, it turns out that only when subscribed by typing.ClassVar is an annotate variable considered a class variable. Copied from the above-mentioned documentation:

class Starship:
    stats: ClassVar[dict[str, int]] = {} # class variable
    damage: int = 10                     # instance variable

What I had as an example in the original post is therefore an instance variable, not a class variable. This contradicts the discussion in PyCQA/flake8-bugbear#293, which only has to do with typing.ClassVar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions