| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM, we can merge this when you undraft it.
Sorry, something went wrong.
|
Done, thanks! |
Sorry, something went wrong.
## 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.)
| Back | FazBrowse Home | New Git URL |
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