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

Fix false-positive assigning-non-slot with typing.Generic base #4522

Merged
merged 1 commit into from
May 30, 2021
Merged

Fix false-positive assigning-non-slot with typing.Generic base #4522

merged 1 commit into from
May 30, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented May 29, 2021

Description

Fix a false-positive for assigning-non-slot with base that inherits from typing.Generic.

from typing import Generic, TypeVar
T = TypeVar("T")

class Base(Generic[T]):
    __slots__ = ()

class Foo(Base[T]):
    __slots__ = ['_value']

    def __init__(self, value: T):
        self._value = value

The reason for the issue is that slots() is evaluated and cached before any inference tips from astroid are applied.
For classes that directly inherit from Generic this is fixed by astroid, everything else needs to be handled by pylint at least for now. -> astroid fix

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes #4509
Closes pylint-dev/astroid#999

@cdce8p cdce8p added the False Positive 🦟 A message is emitted but nothing is wrong with the code label May 29, 2021
@cdce8p
Copy link
Member Author

cdce8p commented May 29, 2021

/CC: @hippo91

@coveralls
Copy link

coveralls commented May 29, 2021

Coverage Status

Coverage increased (+0.002%) to 91.835% when pulling 721d9c3 on cdce8p:fix-assigning-non-slot into d09c5de on PyCQA:master.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cdce8p cdce8p merged commit 9d1acfc into pylint-dev:master May 30, 2021
@cdce8p cdce8p deleted the fix-assigning-non-slot branch May 30, 2021 00:43
@cdce8p cdce8p mentioned this pull request Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slots and Generics handling broken since 2.8.0 Slots and Generics handling broken since 2.5.3
3 participants