python / python/cpython

Merge 'types.UnionType' with `typing._UnionGenericAlias`, not `typing.Union`

Open
#137,065 21 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 3.15 topic-typing type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

I think #105499 was a mistake. types.UnionType was intentionally named so to avoid confusion with typing.Union (see #88895). types.UnionType should not be subscriptable because it is not generic type (and if it was a generic type, subscription would have different semantic than for typing.Union). types.UnionType corresponds to typing._UnionGenericAlias, not typing.Union (see https://github.com/python/cpython/issues/89581#issuecomment-1093932536).

So we should restore typing.Union, make typing._UnionGenericAlias an alias of types.UnionType, and make types.UnionType non-subscriptable again.

Linked PRs
  • gh-137069
  • gh-138967

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the issue's references to #105499, #88895, and #89581, then inspect the linked work in gh-137069 and gh-138967. Trace the relationship between types.UnionType, typing.Union, and typing._UnionGenericAlias; done means the intended aliasing and non-subscriptable behavior are restored and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.