mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Star-star syntax not allowed with TypedDict

Open intgr opened this issue 5 years ago • 2 comments

🐛 Bug Report

This is similar to #6462 and #9335 but with the star-star syntax.

There are cases where mypy could prove the following program type-safe, but currently this is never allowed:

To Reproduce

from typing import TypedDict


class Value(TypedDict):
    key1: str
    key2: str


const1: Value = {"key1": "foo", "key2": "bar"}
const2: Value = {**const1, "key2": "eggs"}
#                ^^^^^^^^
# mypy: Expected TypedDict key to be string literal (10:20)
  • Mypy version used: mypy 0.780
  • Python version used: 3.8.6

intgr avatar Sep 03 '20 14:09 intgr

I'm raising the priority of this issue, since it has been requested many times and there have been at least three duplicate issues.

AlexWaygood avatar May 03 '22 17:05 AlexWaygood

I've just given this issue a go in my pull request: https://github.com/python/mypy/pull/13353

eflorico avatar Aug 07 '22 19:08 eflorico