KEMBAR78
Upcasting causes incompatible types in assignment with `TypedDict` · Issue #14991 · python/mypy · GitHub
Skip to content

Upcasting causes incompatible types in assignment with TypedDict #14991

@sterliakov

Description

@sterliakov

Bug Report

Type checking the code below causes mypy errors. In my opinion, everything assignable to type T should be still assignable to type T | something.

To Reproduce

Playground with the following code:

from typing import TypedDict


class AngleDict(TypedDict):
    yaw: float
    pitch: float
    roll: float
    

angles: dict[str, None] = {"yaw": None, "pitch": None, "roll": None}
angles2: AngleDict | dict[str, None] = {"yaw": None, "pitch": None, "roll": None}

Expected Behavior

No errors.

Actual Behavior

main.py:11: error: Incompatible types (expression has type "None", TypedDict item "yaw" has type "float")  [typeddict-item]
main.py:11: error: Incompatible types (expression has type "None", TypedDict item "pitch" has type "float")  [typeddict-item]
main.py:11: error: Incompatible types (expression has type "None", TypedDict item "roll" has type "float")  [typeddict-item]
Found 3 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: master and 1.1.1
  • Mypy command-line flags: nope
  • Mypy configuration options from mypy.ini (and other config files): nope
  • Python version used: 3.10, 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions