Skip to content

Star-star syntax not allowed with TypedDict #9408

Closed
@intgr

Description

@intgr

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions