Skip to content

Pyright can't tell what's required when mixing **kwargs: Unpack with partial #9181

Open

Description

Discussed in #9180

Originally posted by naddeoa October 8, 2024
When you use Unpack to define the kwargs of a function (fn below) then pyright loses the ability to tell which args are actually required or not after you also use partial on that function. I'm not even sure if this a pyright issue or a typeshed issue. In general, things kind of get weird depending on the pyright version when you start using Unpack.

from functools import partial
from typing import List, TypedDict
from typing_extensions import NotRequired, Unpack


class Foo(TypedDict):
    c: List[str]
    a: int
    b: NotRequired[str]


def fn(**kwargs: Unpack[Foo]) -> None:
    print(f"a: {kwargs['a']}, b: {kwargs.get( 'b' )}, c: {kwargs['c']}")


def hardcoded(c: List[str], a: int, b: str) -> None:
    print(f"a: {a}, b: {b}, c: {c}")


fn2 = partial(fn, c=["a", "b"], a=2)
hardcoded2 = partial(hardcoded, c=["a", "b"], a=2)


fn2(b="2")  # BUG pyright says that a/c are missing in fn2
hardcoded2(b="2")
```</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions