Skip to content

Outdated example code of typing.TypedDict #107422

@wanglc02

Description

@wanglc02

Documentation

https://docs.python.org/3.12/library/typing.html#typing.TypedDict

Changed in version 3.11: Added support for generic TypedDicts.

The text description has already changed, too:
A TypedDict cannot inherit from a non-TypedDict class, except for Generic. For example:

class X(TypedDict):
    x: int

class Y(TypedDict):
    y: int

class Z(object): pass  # A non-TypedDict class

class XY(X, Y): pass  # OK

class XZ(X, Z): pass  # raises TypeError

T = TypeVar('T')
class XT(X, Generic[T]): pass  # raises TypeError

On the last line of the above code, # raises TypeError should be # OK. I have tested this in version 3.12. It is OK.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions