Skip to content

TypedDict unpacking should be checked more strictly #5198

@Michael0x2a

Description

@Michael0x2a

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?)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions