Skip to content

Enable PEP 692 Support #14697

Closed
Closed

Description

@hmc-cs-mdrissi

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.

Activity

  1. PhilReinhold commented on Mar 21, 2023

    @PhilReinhold

    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]
    
  2. erictraut commented on Mar 21, 2023

    @erictraut

    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.

  3. Avasam commented on Oct 2, 2023

    @Avasam
    SponsorContributor

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

  4. AlexWaygood commented on Oct 3, 2023

    @AlexWaygood
    Member

    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 :)

  5. Avasam commented on Oct 3, 2023

    @Avasam
    SponsorContributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions