Skip to content

Incorrect error when argument missing from function call unpacking TypedDict #12755

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

Open
Zeckie opened this issue May 9, 2022 · 0 comments
Open
Labels
bug mypy got something wrong topic-typed-dict

Comments

@Zeckie
Copy link

Zeckie commented May 9, 2022

Bug Report

When supplying arguments by unpacking a TypedDict, and the TypedDict does not supply all the parameters, mypy seems to treat it as only supplying the first parameter, even if that is the one that is missing.

To Reproduce

from typing import TypedDict

def my_function(foo: int, bar: int) -> None:
    pass

class MyTypedDict(TypedDict):
    # foo: int
    bar: int

    
a: MyTypedDict = {'bar': 1}

my_function(**a) # mypy - error: Missing positional argument "bar" in call to "my_function"
my_function(bar=1) # mypy - error: Missing positional argument "foo" in call to "my_function"

https://mypy-play.net/?mypy=0.931&python=3.11&flags=strict&gist=c72be0814d2e7684453f2a8825f2e986

Expected Behavior

The line my_function(**a) should result in mypy error error: Missing positional argument "foo" in call to "my_function", as it only supplies bar.

Actual Behavior

The line my_function(**a) resulted in mypy error error: Missing positional argument "bar" in call to "my_function".

When executed, python gave this error:

TypeError: my_function() missing 1 required positional argument: 'foo'

#11753

@Zeckie Zeckie added the bug mypy got something wrong label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-typed-dict
Projects
None yet
Development

No branches or pull requests

2 participants