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

[flake8-slots] Flag subclasses of call-based typing.NamedTuples as well as subclasses of collections.namedtuple() (SLOT002) #10808

Merged
merged 1 commit into from Apr 6, 2024

Conversation

AlexWaygood
Copy link
Member

Summary

Fixes #10805.

While __slots__ are automatically added to this class by the typing module...

class Foo(typing.NamedTuple):
    x: int

...they are not automatically added to this class...

class Foo(typing.NamedTuple("foo", [("x", int)])):
    pass

...so it seems reasonable for SLOT002 to emit a lint on that class just the same as it does for this class:

class Foo(collections.namedtuple("foo", ["x"])):
    pass

Test Plan

cargo test

…s well as subclasses of `collections.namedtuple()` (`SLOT002`)
@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Apr 6, 2024
Copy link

github-actions bot commented Apr 6, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood AlexWaygood merged commit 8658869 into astral-sh:main Apr 6, 2024
17 checks passed
@AlexWaygood AlexWaygood deleted the typing-namedtuple-slots branch April 6, 2024 23:16
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 12, 2024
…s well as subclasses of `collections.namedtuple()` (`SLOT002`) (astral-sh#10808)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flake8-slots] Rule SLOT002 doesn't take typing.NamedTuple into account
2 participants