Skip to content

Multiple inheritance with TypedDict: constructing dict of components fails type check #13045

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

Closed
Vince-sys opened this issue Jun 30, 2022 · 1 comment
Labels
bug mypy got something wrong topic-typed-dict

Comments

@Vince-sys
Copy link

Bug Report

A dict(**component_a, **component_b) does not type match with a type AB, where component_a : A, component_b: B, and class AB(A, B), and types A & B are simple TypedDicts

To Reproduce

from typing import TypedDict

class A(TypedDict):
    field1: str
    field2: str

class B(TypedDict):
    field3: str
    field4: str

class AB(A, B):
    pass

def get_thing(a: A, b: B) -> AB:
    return dict(**a, **b)

Expected Behavior
Success: no issues found in 1 source file

Actual Behavior
foo.py:15: error: Incompatible return value type (got "Dict[str, str]", expected "AB")

Your Environment
mypy 0.961 (compiled: yes)
default config for mypy
Python 3.9.10
Darwin Vincents-MacBook-Pro 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

@Vince-sys Vince-sys added the bug mypy got something wrong label Jun 30, 2022
@AlexWaygood
Copy link
Member

Duplicate of #9408

@AlexWaygood AlexWaygood marked this as a duplicate of #9408 Jun 30, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-typed-dict
Projects
None yet
Development

No branches or pull requests

2 participants