-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
3.14 regression: Union[int, str] is Union[int, str]
does not hold
#131933
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
Comments
Union[int, str] is Union[int, str]
does not hold
See python/cpython#131933. Python does not guarantee that running `Union[A, B]` twice gives the same object back. This test is currently broken in Python 3.14 main.
See python/cpython#131933. Python does not guarantee that running `Union[A, B]` twice gives the same object back. This test is currently broken in Python 3.14 main.
I think that test is incorrect and I posted python-attrs/cattrs#642 to fix it. We never guaranteed anything about the behavior of This does indicate a possible real-world issue that I hadn't considered, though. The We could re-add a cache to the C implementation of
This makes me think that it's not worth re-adding the cache system that would make it so running We can add a note to the What's New for 3.14 though pointing out this behavior change. |
One more point around memory usage: new-style union objects are themselves much smaller. Old |
Co-authored-by: Alex Waygood Co-authored-by: Bénédikt Tran <[email protected]>
Oh and one more thing (in case someone else complains about this later): the >>> from typing import Literal, Union
>>> lst = [Union[int, str], *[Union[str, Literal[i]] for i in range(1000)], Union[int, str]]
>>> lst[0]
typing.Union[int, str]
>>> lst[-1]
typing.Union[int, str]
>>> lst[0] is lst[-1]
False |
…n#131941) Co-authored-by: Alex Waygood Co-authored-by: Bénédikt Tran <[email protected]>
Bug report
Bug description:
Python 3.13.2
Python 3.14.0a6
Is this change desired, is it documented? This breaks tests in https://github.com/python-attrs/cattrs/blob/d8f17b7e7e57006171027df4d647a6fe068b623e/tests/test_disambiguators.py#L211
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: