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

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

Open
cmp0xff opened this issue Nov 20, 2024 · 1 comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@cmp0xff
Copy link
Contributor

cmp0xff commented Nov 20, 2024

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.

@dylwil3 dylwil3 added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Nov 20, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 20, 2024

To clarify, the suggestion here is this:

from abc import ABC

class Foo(ABC):
    a: ClassVar[int]              #<--- should not trigger B024

class Bar(ABC):
    b: int              #<--- should trigger B024 because it is not annotated as a class variable

this makes some sense to me but I'd have to read the documentation to make sure I'm understanding correctly, so I'm not sure whether to adopt this behavior just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants