Skip to content

gh-132941: Soft deprecate various typing classes#154480

Open
srittau wants to merge 6 commits into
python:mainfrom
srittau:typing-deprecations
Open

gh-132941: Soft deprecate various typing classes#154480
srittau wants to merge 6 commits into
python:mainfrom
srittau:typing-deprecations

Conversation

@srittau

@srittau srittau commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Also use the newer type var syntax in a few places.

This PR does not deprecated TypeVar, ParamSpec, and TypeVarTuple
constructors, as it is sometimes necessary to create type vars using the
explicit syntax. (For example to create a shared type var like AnyStr or
to use it as a type form.)

Cc @JelleZijlstra

Also use the newer type var syntax in a few places.
@read-the-docs-community

read-the-docs-community Bot commented Jul 22, 2026

Copy link
Copy Markdown

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

Comment thread Doc/library/types.rst

.. deprecated:: 3.16

Use :class:`typing.Union` instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should suggest using |?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The | syntax creates instances of typing.Union, which types.UnionType is now an alias for (as the line before indicates).

I think this is clear enough when combined with the previous line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both would be beneficial:

Use the ``X | Y`` syntax to create ``Union`` instances and :class:typing.Union for all other purposes.

Comment thread Doc/library/typing.rst
See :pep:`585` and :ref:`types-genericalias`.

.. class:: Type(Generic[CT_co])
.. class:: Type[CT_co]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when I tried to do this during the PEP 695 implementation it wasn't possible because Sphinx couldn't parse the syntax, definitely supportive of changing this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread Doc/library/types.rst Outdated

This is now an alias for :class:`typing.Union`.

.. deprecated:: 3.16

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it soft-deprecated or deprecated?

Suggested change
.. deprecated:: 3.16
.. soft-deprecated:: 3.16

If it's soft deprecated, also add them to the relevant file in the deprecations docs. If it's regular-deprecated, please schedule removal for a version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants