Skip to content

gh-137065: Unmerge types.UnionType and typing.Union - #137069

Draft
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:typing-union
Draft

gh-137065: Unmerge types.UnionType and typing.Union#137069
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:typing-union

Conversation

@serhiy-storchaka

@serhiy-storchakaserhiy-storchaka commented Jul 24, 2025

Copy link
Copy Markdown
Member

Partially revert GH-105499.

types.UnionType no longer an alias of typing.Union and no longer subscriptable, but subscribing typing.Union returns an instance of types.UnionType. typing.Union can no longer be used in the isinstance() checks.


📚 Documentation preview 📚: https://cpython-previews--137069.org.readthedocs.build/

Partially revert pythonGH-105499.
types.UnionType no longer an alias of typing.Union and no longer subscriptable,
but subscribing typing.Union returns an instance of types.UnionType.
typing.Union can no longer be used in the isinstance() checks.

@JelleZijlstraJelleZijlstra 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.

I don't think anything should be changed here.

@bedevere-app

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment threadDoc/whatsnew/3.14.rst
- Both syntaxes for creating a union now produce the same string representation in
``repr()``. For example, ``repr(Union[int, str])``
is now ``"int | str"`` instead of ``"typing.Union[int, str]"``.
- Unions created using the old syntax are no longer cached. Previously, running

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.

Not sure why this was removed; the text would seem to still apply under this PR.

@serhiy-storchaka

Copy link
Copy Markdown
MemberAuthor

I now think that we need a full revert. See #138967.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 27, 2026
@serhiy-storchakaserhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 30, 2026
@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label Jun 1, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO-NOT-MERGEneeds backport to 3.14bugs and security fixesneeds backport to 3.15pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@JelleZijlstra