Skip to content

PEP 692 (kwargs TypedDict) tracker #9710

Open
@hmc-cs-mdrissi

Description

@hmc-cs-mdrissi

Test example I'm using for support,

from typing import TypedDict

from typing_extensions import Unpack


class Foo(TypedDict, total=False):
    a: int
    b: str


def f(**kwargs: Unpack[Foo]) -> None:
    ...


f(a=1, b="2")  # OK
f(a=1, b=2)  # Error: b has type str
f(a=1, b="2", c=3)  # Error: unexpected keyword argument "c"

pytype and pyre both produce 1 error on f(**kwargs: Unpack[Foo]) . Pytype produces typing_extensions.Unpack not supported yet [not-supported-yet] while pyre produces pep_692.py:11:16 Undefined or invalid type [11]: Annotation Unpack is not defined as a type.

Unsure if typeshed usage for this should wait til pyre/pytype fully support pep 692 or if current status of them not checking lines reliant on 692 is enough (similar to Self type status). pytype/pyre still detect errors normally for other parts of the file.

For mypy side we would also need to adjust line with mypy flags to include --enable-incomplete-feature=Unpack (maybe other incomplete features should be considered too).

Motivation for issue was yesterday I hit some lines in tensorflow stub where 692 would be helpful. Minor though and being explicit on arguments works fine (just adds a couple stubtest allowlist lines).

Metadata

Metadata

Assignees

No one assigned

    Labels

    project: feature trackerTracks whether a typing feature can be used in typeshed stubs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions