2Tests inheritance rules for TypedDict classes.
5# Specification: https://typing.readthedocs.io/en/latest/spec/typeddict.html#typeddict
7from typing import TypedDict
10class Movie(TypedDict):
14class BookBasedMovie(Movie):
17class BookBasedMovieAlso(TypedDict):
22b1: BookBasedMovie = {"name": "Little Women", "year": 2019, "based_on": "Little Women"}
24b2: BookBasedMovieAlso = b1
36x1 = XYZ(x=1, y="", z=True)
38# > A TypedDict cannot inherit from both a TypedDict type and a
39# > non-TypedDict base class other than Generic.
44class BadTypedDict(TypedDict, NonTypedDict): # E
[invalid-typed-dict-header] TypedDict class `BadTypedDict` can only inherit from TypedDict classes: `NonTypedDict` is not a `TypedDict` class
48# > Changing a field type of a parent TypedDict class in a subclass is
Expected a ty diagnostic for this line (tag 'Y1')
55 x: int # E[Y1]: cannot overwrite TypedDict field "x"
Expected a ty diagnostic for this line (tag 'Y1')
58# > Multiple inheritance does not allow conflict types for the same name field:
65class XYZ2(X2, Y2): # E: cannot overwrite TypedDict field "x" while merging
Expected a ty diagnostic for this line