Skip to content

Python 3.14 regression in supported types for | syntax for typing.Union and strings #140348

@onerandomusername

Description

@onerandomusername

Bug report

Bug description:

On Python 3.14, it seems that pipe unions with typing.Union and str objects raise a TypeError. This is a regression from Python 3.13 behaviour, where Union could be or'd with a str to create a Union with a ForwardRef.

Python 3.13 behaviour

>>> from typing import Union
>>> Union[int, str] | 'tuple'
typing.Union[int, str, ForwardRef('tuple')]

Python 3.14 behaviour

>>> from typing import Union
>>> Union[int, str] | 'tuple'
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    Union[int, str] | 'tuple'
    ~~~~~~~~~~~~~~~~^~~~~~~~~
TypeError: unsupported operand type(s) for |: 'typing.Union' and 'str'

Version information

>>> sys.version_info
sys.version_info(major=3, minor=14, micro=0, releaselevel='final', serial=0)

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions