FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add NamedTuple `__match_args__` attribute by charliermarsh · Pull Request #15906 · python/typeshed · GitHub

Add NamedTuple __match_args__ attribute - #15906

Merged
AlexWaygood merged 1 commit into
python:mainfrom
charliermarsh:charlie/add-namedtuple-match-args
Jun 13, 2026
Merged

Add NamedTuple __match_args__ attribute#15906
AlexWaygood merged 1 commit into
python:mainfrom
charliermarsh:charlie/add-namedtuple-match-args

Conversation

Copy link
Copy Markdown
Contributor

Summary

Python 3.10 adds __match_args__ to classes created by NamedTuple.

This adds the class variable to _typeshed._type_checker_internals.NamedTupleFallback and the obsolete typing.NamedTuple compatibility copy.

This was found while implementing __match_args__ support for named tuples in ty: astral-sh/ruff#25934

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, we can merge this when you undraft it.

charliermarsh marked this pull request as ready for review June 13, 2026 11:28

Copy link
Copy Markdown
Contributor Author

Done, thanks!

AlexWaygood merged commit 95aa599 into python:main Jun 13, 2026
58 checks passed
charliermarsh added a commit to astral-sh/ruff that referenced this pull request Jun 13, 2026
## Summary

Python 3.10 generates `__match_args__` on named tuples so their fields
can be used in positional class patterns. We already synthesize other
generated named-tuple attributes, but did not expose `__match_args__`.

```python
from typing import NamedTuple

class Point(NamedTuple):
    x: int
    y: str

reveal_type(Point.__match_args__)  # tuple[Literal["x"], Literal["y"]]
```

The gradual fallback for named tuples with unknown fields comes from
`NamedTupleFallback`, as proposed in
python/typeshed#15906. (I've included a
temporary copy of that typeshed change until approved.)
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL