Skip to content

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

Merged
AlexWaygood merged 1 commit intoastral-sh:mainfrom
AlexWaygood:typing-namedtuple-slots
Apr 6, 2024
Merged

[flake8-slots] Flag subclasses of call-based typing.NamedTuples as well as subclasses of collections.namedtuple() (SLOT002)#10808
AlexWaygood merged 1 commit intoastral-sh:mainfrom
AlexWaygood:typing-namedtuple-slots

Conversation

@AlexWaygood
Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown
Contributor

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
@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