Skip to content

typing docs: Use soft deprecation #132941

Open
@JelleZijlstra

Description

@JelleZijlstra

A while ago we introduced the concept of "soft deprecation" in PEP 387 (https://peps.python.org/pep-0387/#soft-deprecation): for things that we no longer recommend using, but which we aren't planning to remove in the near future.

The typing docs already list four classes of objects that are deprecated without a scheduled removal (https://docs.python.org/3.14/library/typing.html#deprecation-timeline-of-major-features):

  • Pre-PEP-585 generic aliases (e.g. List)
  • Text
  • Hashable and Sized
  • TypeAlias

I'd like to also soft-deprecate the following:

  • Optional (obviated by PEP-604)
  • NoReturn (prefer Never)
  • typing.ForwardRef (deprecated alias for annotationlib.ForwardRef)
  • types.UnionType (deprecated alias for typing.Union)
  • Creating a Union using subscripting (Union[A, B] instead of A | B) (PEP-604)
  • Creating a TypeVar, ParamSpec, or TypeVarTuple using the constructor directly (PEP-695)
  • Directly inheriting from Generic (PEP-695)

None of those will be removable for many years if ever, but I think it's useful to have a clear statement in the docs that the newer syntax is preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions