onerandomusername · GitHub

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

Read the original on github.com ↗