Open
Description
openedon Oct 9, 2024
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