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

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

Open
erictraut opened this issue Oct 9, 2024 Discussed in #9180 · 0 comments
Open

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

erictraut opened this issue Oct 9, 2024 Discussed in #9180 · 0 comments
Labels
bug Something isn't working

Comments

@erictraut
Copy link
Collaborator

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>
@erictraut erictraut added the bug Something isn't working label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant