Skip to content

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

Closed as not planned
@Vince-sys

Description

@Vince-sys

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions