Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upcasting causes incompatible types in assignment with TypedDict #14991

Open
sterliakov opened this issue Apr 1, 2023 · 0 comments
Open

Upcasting causes incompatible types in assignment with TypedDict #14991

sterliakov opened this issue Apr 1, 2023 · 0 comments
Labels
bug mypy got something wrong

Comments

@sterliakov
Copy link
Contributor

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
@sterliakov sterliakov added the bug mypy got something wrong label Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant