Skip to content

Why is the dict extension prohibited in the TypedDict constructor? #16785

Open
@Chloy

Description

@Chloy

Bug Report

Cannot use dict expansion in TypedDict constructor. Why?

To Reproduce

from typing import TypedDict


class SomeTypedDict(TypedDict):
    field1: str
    field2: int
    field3: bool


SOME_SAMPLE = {
    'field1': 'str',
    'field2': 0,
    'field3': True,
}

some_variable = SomeTypedDict(**SOME_SAMPLE)
print(some_variable)

Actual Behavior

user@pc:~/$ mypy main.py 
main.py:16: error: Unsupported type "dict[str, object]" for ** expansion in TypedDict  [typeddict-item]
Found 1 error in 1 file (checked 1 source file)

Your Environment

user@pc:~/$ mypy --version 
mypy 1.8.0 (compiled: yes)
user@pc:~/$ python3 --version
Python 3.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions