[ty] Use _cls as argument name for collections.namedtuple#24333
Merged
charliermarsh merged 1 commit intomainfrom Mar 31, 2026
Merged
[ty] Use _cls as argument name for collections.namedtuple#24333charliermarsh merged 1 commit intomainfrom
_cls as argument name for collections.namedtuple#24333charliermarsh merged 1 commit intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.61%. The percentage of expected errors that received a diagnostic held steady at 81.56%. The number of fully passing files held steady at 70/132. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 40 | 0 |
invalid-argument-type |
0 | 4 | 0 |
missing-argument |
0 | 3 | 0 |
parameter-already-assigned |
0 | 3 | 0 |
invalid-return-type |
0 | 1 | 0 |
| Total | 0 | 51 | 0 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
Raw diff:
core (https://github.com/home-assistant/core)
- homeassistant/components/xbox/browse_media.py:33:12 error[missing-argument] No argument provided for required parameter `cls`
- homeassistant/components/xbox/browse_media.py:35:9 error[invalid-argument-type] Argument is incorrect: Expected `type[MediaTypeDetails]`, found `Literal[MediaClass.APP]`
- homeassistant/components/xbox/browse_media.py:35:9 error[parameter-already-assigned] Multiple values provided for parameter `cls`
- homeassistant/components/xbox/browse_media.py:37:13 error[missing-argument] No argument provided for required parameter `cls`
- homeassistant/components/xbox/browse_media.py:39:9 error[invalid-argument-type] Argument is incorrect: Expected `type[MediaTypeDetails]`, found `Literal[MediaClass.GAME]`
- homeassistant/components/xbox/browse_media.py:39:9 error[parameter-already-assigned] Multiple values provided for parameter `cls`
django-stubs (https://github.com/typeddjango/django-stubs)
- mypy_django_plugin/lib/helpers.py:226:16 error[missing-argument] No argument provided for required parameter `cls`
- mypy_django_plugin/lib/helpers.py:226:20 error[invalid-argument-type] Argument is incorrect: Argument type `Model` does not satisfy upper bound `DjangoModel` of type variable `Self`
- mypy_django_plugin/lib/helpers.py:226:20 error[invalid-argument-type] Argument is incorrect: Expected `type[DjangoModel]`, found `type[Model]`
- mypy_django_plugin/lib/helpers.py:226:20 error[parameter-already-assigned] Multiple values provided for parameter `cls`
AlexWaygood
approved these changes
Mar 31, 2026
Comment on lines
+1194
to
+1195
| Field names that would otherwise collide with the synthetic constructor receiver still work as | ||
| keyword arguments, matching CPython's generated `__new__(_cls, ...)` signature: |
Member
There was a problem hiding this comment.
I would just describe this with
Suggested change
| Field names that would otherwise collide with the synthetic constructor receiver still work as | |
| keyword arguments, matching CPython's generated `__new__(_cls, ...)` signature: | |
| Regression test for https://github.com/astral-sh/ty/issues/3184: the first parameter of `__new__` | |
| at runtime for a namedtuple class is `_cls`, meaning that `cls` can be used as a field name: |
Comment on lines
+1202
to
+1208
| PInfo(inst=None, cls=str) | ||
|
|
||
| class StaticInfo(NamedTuple): | ||
| inst: object | None | ||
| cls: type[str] | ||
|
|
||
| StaticInfo(inst=None, cls=str) |
Member
There was a problem hiding this comment.
Suggested change
| PInfo(inst=None, cls=str) | |
| class StaticInfo(NamedTuple): | |
| inst: object | None | |
| cls: type[str] | |
| StaticInfo(inst=None, cls=str) | |
| reveal_type(PInfo(inst=None, cls=str)) # revealed: PInfo | |
| class StaticInfo(NamedTuple): | |
| inst: object | None | |
| cls: type[str] | |
| reveal_type(StaticInfo(inst=None, cls=str)) # revealed: StaticInfo |
20424a3 to
97c2e2b
Compare
carljm
added a commit
that referenced
this pull request
Apr 1, 2026
* main: [ty] Add missing test case for inline functional TypedDict with an invalid type passed to the `name` parameter (#24334) [ty] Use `_cls` as argument name for `collections.namedtuple` (#24333) [ty] Emit diagnostic for functional TypedDict with non-literal name (#24331) Add `nested-string-quote-style` formatting option (#24312) `RUF010`: Mark fix as unsafe when it deletes a comment [ty] Fix semantic token classification for properties accessed on instances (#24065) publish installers to `/installers/ruff/latest` on the mirror (#24247)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I believe this is defined here: https://github.com/python/cpython/blob/362145c20ebb08d2f850a49d356ecee858a281ae/Lib/collections/__init__.py#L446.
Closes astral-sh/ty#3184.