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

TypedDict unpacking should be checked more strictly #5198

Closed
Michael0x2a opened this issue Jun 11, 2018 · 1 comment
Closed

TypedDict unpacking should be checked more strictly #5198

Michael0x2a opened this issue Jun 11, 2018 · 1 comment

Comments

@Michael0x2a
Copy link
Collaborator

I'm not sure if this should be classified as a missing feature or a bug, but the behavior of the following program is surprising to me:

from mypy_extensions import TypedDict

def foo(x: int, y: int) -> None: pass

OkDict = TypedDict('OkDict', {'x': int, 'y': int})
BadDict1 = TypedDict('BadDict1', {'x': int})
BadDict2 = TypedDict('BadDict2', {'x': int, 'y': str})

a: OkDict
b: BadDict1
c: BadDict2

foo(**a)  # Type checks, as expected
foo(**b)  # Type checks; should be an error
foo(**c)  # Type checks; should be an error

Mypy currently reports no errors with this program; I think we should report an error with the last two calls.

(I'm assuming we're currently ignoring the 'shape' of the TypedDicts and are handling them in the same way we handle Dict?)

@ilevkivskyi
Copy link
Member

I would rather classify this as a feature (especially taking into account that TypedDict still doesn't have its PEP). Anyway, I believe this is something important to have.

@JukkaL JukkaL self-assigned this Nov 16, 2018
JukkaL added a commit that referenced this issue Nov 30, 2018
Expand and type check TypedDict types when used as **kwargs in calls.

Also refactored the implementation of checking function arguments and
removed some apparently useless code.

Fixes #5198 and another related issue: type checking calls with multiple
*args arguments.
ilevkivskyi added a commit that referenced this issue Aug 18, 2019
I think this can be re-enabled since #5198 was fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants