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 declare-non-slot on classvar #9950

Open
mthuurne opened this issue Sep 23, 2024 · 3 comments
Open

False positive declare-non-slot on classvar #9950

mthuurne opened this issue Sep 23, 2024 · 3 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@mthuurne
Copy link
Contributor

mthuurne commented Sep 23, 2024

Bug description

I'm checking code that simplifies to this testcase:

from typing import ClassVar


class C:
    __slots__ = ("value",)

    def __init__(self, value: int):
        self.value = value

    x: ClassVar[int]
    y: ClassVar[int] = 2
    z = 3

For some reason, pylint considers x to be a declaration that conflicts with __slots__, but not y and z.

Curiously, this error flagged for x goes away if __slots__ is empty.

Configuration

No response

Command used

pylint non_slot_classvar.py

Pylint output

************* Module non_slot_classvar
non_slot_classvar.py:10:4: E0245: No such name 'x' in __slots__ (declare-non-slot)

Expected behavior

No error should be flagged.

At runtime, there is no error, as __slots__ only applies to instances of C, not to the class.

Pylint version

pylint 3.3.0
astroid 3.3.3
Python 3.11.9 (main, Apr 08 2024, 06:18:15) [GCC]

OS / Environment

Linux (openSUSE Tumbleweed)

Additional dependencies

No response

@mthuurne mthuurne added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 23, 2024
@mthuurne
Copy link
Contributor Author

This problem is new since pylint 3.3.0, which makes sense as E0245 was added recently, in #9564.

@jacobtylerwalls
Copy link
Member

cc/ @adamtuft, could you lend us your view of this bug report? Thanks!

@adamtuft
Copy link
Contributor

adamtuft commented Sep 27, 2024

Thanks for tagging me, I'll have a look at this 🔍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

3 participants