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

Enable PEP 692 Support #14697

Closed
hmc-cs-mdrissi opened this issue Feb 14, 2023 · 5 comments · Fixed by #16354
Closed

Enable PEP 692 Support #14697

hmc-cs-mdrissi opened this issue Feb 14, 2023 · 5 comments · Fixed by #16354
Labels

Comments

@hmc-cs-mdrissi
Copy link
Contributor

Feature
PEP 692 support currently works but is gated behind --enable-incomplete-feature=Unpack. I think that flag includes both kwargs unpacking and variadic generics unpacking. It would be nice to move out just kwargs unpacking and have it available by default. That would enable typeshed/easier library usage of it.

Related typeshed issue.

@PhilReinhold
Copy link

Is all of 692 supported? According to https://peps.python.org/pep-0646/#unpacking-unbounded-tuple-types I think the following should work

from typing_extensions import Unpack
x: tuple[str, Unpack[tuple[int, ...]]]
x = ("a", 1, 2, 3)

But I currently get (on mypy 1.1.1 on python 3.10.9)

mypy test.py --enable-incomplete-feature=Unpack
test.py:5: error: Incompatible types in assignment (expression has type "Tuple[str, int, int, int]", variable has type "Tuple[str, Unpack[Tuple[int, ...]]]")  [assignment]

@erictraut
Copy link

PEP 692 applies only to annotations on **kwargs parameters. PEP 646 covers other uses of Unpack including variadic type variables (TypeVarTuple). As far as I know, mypy's support for PEP 646 is not yet complete. See this tracking issue for details.

@Avasam
Copy link
Sponsor Contributor

Avasam commented Oct 2, 2023

I feel like this could remove many stubtest allowlist lines in TypeShed (where kwargs are manually unpacked) when fully supported.

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 3, 2023

I feel like this could remove many stubtest allowlist lines in TypeShed (where kwargs are manually unpacked) when fully supported.

Ooh, a little off-topic, but I'd be curious if you have any examples @Avasam! Stubtest actually already has some special-case logic to specifically allow kwargs to be manually unpacked in a stub if the runtime just has **kwargs. Most times I've seen this kind of thing being allowlisted in typeshed, it's because contributors forgot to make all the "manually unpacked" parameters keyword-only in the stub (bcd4ff2 should help a bit with the error messages here, hopefully :)

@Avasam
Copy link
Sponsor Contributor

Avasam commented Oct 3, 2023

Most times I've seen this kind of thing being allowlisted in typeshed, it's because contributors forgot to make all the "manually unpacked" parameters keyword-only in the stub

Now that you mention it... I'll double check and come back to you (other here or in typeshed PRs). That might be it.

JukkaL pushed a commit that referenced this issue Oct 30, 2023
Fixes #12280
Fixes #14697

In this PR:
* Enable `TypeVarTuple` and `Unpack` features.
* Delete the old blanket `--enable-incomplete-features` flag that was
deprecated a year ago.
* Switch couple corner cases to `PreciseTupleTypes` feature.
* Add the draft docs about the new feature.
* Handle a previously unhandled case where variadic tuple appears in
string formatting (discovered on mypy self-check, where
`PreciseTupleTypes` is already enabled).

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants