PEP-655 introduced the Required and NotRequired type hints for TypedDicts, this can be used as a simplification in the *Required type hints like.
Example:
class InputAlertRequired(TypedDict):
title: str
description: str
class InputAlert(InputAlertRequired, total=False):
tags: list[str]
can be simplified into a single object like:
class InputAlert(TypedDict, total=False):
title: Required[str]
description: Required[str]
tags: list[str]
or alternatively:
class InputAlert(TypedDict):
title: str
description: str
tags: NotRequired[list[str]]
However these new type hints are not supported by older python versions so it makes sense to introduce typing_extensions as a dependency to the project to retrofit the typehints to older versions.
PEP-655 introduced the
RequiredandNotRequiredtype hints forTypedDicts, this can be used as a simplification in the*Requiredtype hints like.Example:
can be simplified into a single object like:
or alternatively:
However these new type hints are not supported by older python versions so it makes sense to introduce typing_extensions as a dependency to the project to retrofit the typehints to older versions.