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

Use * instead of Unpack[...] in messages when targeting Python 3.11 or later #16445

Open
JukkaL opened this issue Nov 10, 2023 · 2 comments
Open
Labels
feature topic-error-reporting How we report errors topic-pep-646 PEP 646 (TypeVarTuple, Unpack)

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 10, 2023

On Python 3.11 and later it seems better to use the native syntax with * instead of Unpack[...] in various messages.

This is the current behavior:

x: tuple[int, *tuple[int, ...]]
# note: Revealed type is "tuple[builtins.int, Unpack[builtins.tuple[builtins.int, ...]]]"
reveal_type(x)

I'd expect the note to look like this:

Revealed type is "tuple[builtins.int, *builtins.tuple[builtins.int, ...]]"
@JukkaL JukkaL added feature topic-pep-646 PEP 646 (TypeVarTuple, Unpack) labels Nov 10, 2023
@AlexWaygood AlexWaygood added the topic-error-reporting How we report errors label Nov 10, 2023
@ilevkivskyi
Copy link
Member

Yeah, we already do this for error messages, see https://github.com/python/mypy/blob/master/mypy/messages.py#L2519-L2520. I just noticed one tricky thing btw: Unpack can be also used for TypedDict unpacking in **kwargs, in that case we need to keep it as Unpack[...].

@AlexWaygood
Copy link
Member

See also python/cpython#104048 and python/typing_extensions#163, where we changed the runtime repr of Unpack to reflect that it could now be used in a PEP-692 context as well as a PEP-646 context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-error-reporting How we report errors topic-pep-646 PEP 646 (TypeVarTuple, Unpack)
Projects
None yet
Development

No branches or pull requests

3 participants