Skip to content

gh-132941: Soft deprecate various typing classes - #154480

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

srittau wants to merge 11 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 Outdated
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.

@srittau

srittau commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@JelleZijlstra @AlexWaygood Sorry to bother you, but could one of you review and merge this. While I only have 2 PRs open at the moment against CPython, I'm a bit worried about hitting the new 3 PR limit.

@StanFromIreland

Copy link
Copy Markdown
Member

While I only have 2 PRs open at the moment against CPython, I'm a bit worried about hitting the new 3 PR limit.

No need to worry, we'll add you to the exclusion list. :-)

@srittau

srittau commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

While I only have 2 PRs open at the moment against CPython, I'm a bit worried about hitting the new 3 PR limit.

No need to worry, we'll add you to the exclusion list. :-)

Couldn't you have mentioned this after I strong-armed these two into merging this PR? 😇

@JelleZijlstra

Copy link
Copy Markdown
Member

I guess I don't need to do anything here?

@srittau

srittau commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

I guess I don't need to do anything here?

A review and (potential) merge would still be welcome, but became a bit less pressing for me.

Comment thread Doc/deprecations/soft-deprecations.rst Outdated
* :class:`typing.Optional` in favor of the dedicated union syntax
(``X | None``)
* :class:`typing.NoReturn` in favor of :class:`typing.Never`
* :class:`typing.ForwardRef` in favor of :class:`annotationlib.ForwardRef`

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.

These last two are actually just aliases. Perhaps it's clearer to mention them separately?

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.

What exactly do you have in mind? As a whole new top-level item, a new sub-list inside this item, or just change "The following typing-related classes are :term:soft deprecated:" to "The following typing-related classes and aliases ..."?

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 was thinking of just having two lists.

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've done that, but it looks a bit weird to me to separate the aliases from the rest of the typing-related items.

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

.. class:: List(list, MutableSequence[T])
.. class:: List[T](list, MutableSequence[T])

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.

Unrelated but presenting List as a subclass of list is somewhat confusing

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.

Indeed, but it's consistent with the other classes in this doc (e.g. Set[T](set, MutableSet[T])).

srittau and others added 2 commits October 20, 2026 20:31
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Comment thread Doc/deprecations/soft-deprecations.rst Outdated

* The following typing-related aliases are :term:`soft deprecated`:

* :class:`typing.NoReturn` in favor of :class:`typing.Never`

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.

Sorry NoReturn is not an alias, but types.UnionType is.

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've moved it. I think it would be cleanest to use sub-headers, i.e. one for "re module" and one for "Typing-related". And then use one bullet point per item. But I'm not sure if that's in the spirit of the document.

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.

5 participants