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 for optional class attribute #9809

Open
CareF opened this issue Jul 17, 2024 · 1 comment
Open

False positive for optional class attribute #9809

CareF opened this issue Jul 17, 2024 · 1 comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@CareF
Copy link
Contributor

CareF commented Jul 17, 2024

Bug description

"""test_lint.py"""
from typing import Optional

class Foo:
    """class Foo"""
    a: Optional[dict] = None
    def empty(self):
        """foo"""

    @classmethod
    def init(cls):
        """init"""
        if cls.a is None:
            cls.a = {}
        assert cls.a is not None
        assert isinstance(cls.a, dict)
        if cls.a is None:
            return
        cls.a[1] = 2
        _ = cls.a[1]
        _ = 1 in cls.a

Configuration

No response

Command used

pylint test_lint.py

Pylint output

************* Module test_lint
test_lint.py:19:8: E1137: 'cls.a' does not support item assignment (unsupported-assignment-operation)
test_lint.py:20:12: E1136: Value 'cls.a' is unsubscriptable (unsubscriptable-object)
test_lint.py:21:19: E1135: Value 'cls.a' doesn't support membership test (unsupported-membership-test)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

All above errors should not be triggered by cls.a

Pylint version

pylint 3.2.5
astroid 3.2.2
Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)]

OS / Environment

MacOS with homebrew

Additional dependencies

pylint 3.2.5
astroid 3.2.2
Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)]
@CareF CareF added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 17, 2024
@CareF
Copy link
Contributor Author

CareF commented Jul 17, 2024

duplicate with #9515

=====

well not exactly duplicate, since it does not fall into "but we should add one for boolean tests." situation.

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

1 participant