Skip to content

[3.14 regression] Cannot copy Union containing objects that do not implement __or__ #132882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JelleZijlstra opened this issue Apr 24, 2025 · 0 comments
Assignees
Labels
3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Apr 24, 2025

Bug report

Bug description:

In 3.13 it was possible to copy a Union containing any object:

>>> copy.copy(typing.Union[b"x", b"y"])
typing.Union[b'x', b'y']

But in main this fails:

>>> copy.copy(typing.Union[b"x", b"y"])
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    copy.copy(typing.Union[b"x", b"y"])
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jelle/py/cpython/Lib/copy.py", line 100, in copy
    return _reconstruct(x, None, *rv)
  File "/Users/jelle/py/cpython/Lib/copy.py", line 234, in _reconstruct
    y = func(*args)
TypeError: unsupported operand type(s) for |: 'bytes' and 'bytes'
>>> 

This doesn't affect any types supported by the type system (all of which support |), but may affect users who put non-standard objects inside a Union.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

@JelleZijlstra JelleZijlstra added the type-bug An unexpected behavior, bug, or error label Apr 24, 2025
@JelleZijlstra JelleZijlstra self-assigned this Apr 24, 2025
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Apr 24, 2025
@picnixz picnixz added 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir labels Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

2 participants