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 on PLC2801 "unnecessary dunder... for __setattr__" #9584

Closed
dimbleby opened this issue Jan 19, 2024 · 2 comments
Closed

false positive on PLC2801 "unnecessary dunder... for __setattr__" #9584

dimbleby opened this issue Jan 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dimbleby
Copy link

dimbleby commented Jan 19, 2024

ruff 0.1.13

from dataclasses import dataclass, field


@dataclass(frozen=True)
class Foo:
    a: int
    b: int
    c: int = field(init=False)

    def __post_init__(self) -> None:
        object.__setattr__(self, "c", self.a + self.b)

the __setattr__ trick is necessary because the dataclass is frozen, but:

PLC2801 Unnecessary dunder call to `__setattr__`. Mutate attribute directly or use setattr built-in function.

via #9166 presumably

looks like y'all went round this once already at #4752...

@trag1c
Copy link
Contributor

trag1c commented Jan 19, 2024

IMO all instances of object dunder calls should be allowed considering they're so common (would likely prevent a third round of this issue :)).

@charliermarsh
Copy link
Member

I believe this is fixed on main, and in v0.1.14 https://play.ruff.rs/73935842-d2c6-4b42-b5de-545c9a5be633.

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

No branches or pull requests

3 participants