Python 3.14: handle typing.Union immutability#3556
Closed
ncoghlan wants to merge 3 commits intoencode:masterfrom
Closed
Python 3.14: handle typing.Union immutability#3556ncoghlan wants to merge 3 commits intoencode:masterfrom
typing.Union immutability#3556ncoghlan wants to merge 3 commits intoencode:masterfrom
Conversation
Attempting to [publish an experimental project](https://github.com/ncoghlan/tstrprocess/actions/runs/14682311907/job/41206490424#step:3:76) that will require Python 3.14's t-strings to run, I encountered the following exception from this code: ``` AttributeError: 'typing.Union' object has no attribute '__module__' and no __dict__ for setting new attributes. Did you mean: '__reduce__'? ``` This error is due to `typing.Union` instances becoming immutable in Python 3.14+: https://docs.python.org/3.14/whatsnew/3.14.html#typing The PR currently works by ignoring the exception raised (since that's the most robust option), but an alternative approach would be to add a `hasattr` check so only values that already have a `__module__` attribute get modified.
Contributor
|
Thanks @ncoghlan. Are you able to determine which symbol(s) are breaking here? |
Author
|
Ah, trying to reproduce this locally shows that I misread the original traceback. This is actually a dupe of the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
typing.Unioninstances are becoming immutable in Python 3.14+: https://docs.python.org/3.14/whatsnew/3.14.html#typingThis trips up the code in
httpx.__init__that hides the internal module details in top-level object metadata by setting their__module__attributes.Checklist
I don't believe test or documentation changes are needed (when the CI config is expanded to include Python 3.14, this will be covered automatically), but I've left those unchecked until that has been confirmed.
Details
Attempting to publish an experimental project that will require Python 3.14's t-strings to run, I encountered the following exception from this code:
I then traced that new failure back to the
typing.Unionchange described in the summary.The PR currently works by ignoring the exception raised (since that's the most comprehensive option), but an alternative approach would be to add a
hasattrcheck so only values that already have a__module__attribute get modified.