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

PLE0237 false positive for slots literal concatenation #11333

Closed
airallergy opened this issue May 8, 2024 · 1 comment · Fixed by #11488
Closed

PLE0237 false positive for slots literal concatenation #11333

airallergy opened this issue May 8, 2024 · 1 comment · Fixed by #11488
Assignees
Labels
bug Something isn't working

Comments

@airallergy
Copy link

I have a class, whose slots are formed by concatenating other literal tuples via RUF005 style. Below B is reported to violate PLE0237, which is a false positive, I also tried a few variants of B:

  • C: If B is a subclass of any other class, PLE0237 seems to work fine
  • D: If B slots has no other literal items, PLE0237 seems to work fine
  • E: If B slots uses tuple concatenation, which violates RUF005, but PLE0237 seems to work fine
class A:
    pass


class B:
    names = ("x",)
    __slots__ = (*names, "a")

    def __init__(self) -> None:
        self.x = 1  # PLE0237: Attribute `x` is not defined in class's `__slots__`


class C(A):
    names = ("x",)
    __slots__ = (*names, "a")

    def __init__(self) -> None:
        self.x = 1


class D:
    names = ("x",)
    __slots__ = (*names,)

    def __init__(self) -> None:
        self.x = 1


class E:
    names = ("x",)
    __slots__ = names + ("a",)  # RUF005: Consider `(*names, "a")` instead of concatenation

    def __init__(self) -> None:
        self.x = 1
@dhruvmanila
Copy link
Member

Thank you for opening this issue! I think we should ignore raising PLE0237 if __slots__ contain an unpacked argument.

@dhruvmanila dhruvmanila added the bug Something isn't working label May 9, 2024
@charliermarsh charliermarsh self-assigned this May 22, 2024
charliermarsh added a commit that referenced this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants