Closed as duplicate
Description
When using httpx 0.28.1 with Python 3.14.0 (alpha 6 and alpha 7), an AttributeError occurs:
7112109dc9 failed: 'typing.Union' object has no attribute '__module__' and no __dict__ for setting new attributes
divine-core-1 | Traceback (most recent call last):
divine-core-1 | File "/app/divine/divine/networking/core.py", line 71, in request
divine-core-1 | async with httpx.AsyncClient(http2=True, verify=TLS_CONTEXT_HTTP2) as session:
divine-core-1 | ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpx/_client.py", line 1402, in __init__
divine-core-1 | self._transport = self._init_transport(
divine-core-1 | ~~~~~~~~~~~~~~~~~~~~^
divine-core-1 | verify=verify,
divine-core-1 | ^^^^^^^^^^^^^^
divine-core-1 | ...<5 lines>...
divine-core-1 | transport=transport,
divine-core-1 | ^^^^^^^^^^^^^^^^^^^^
divine-core-1 | )
divine-core-1 | ^
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpx/_client.py", line 1445, in _init_transport
divine-core-1 | return AsyncHTTPTransport(
divine-core-1 | verify=verify,
divine-core-1 | ...<4 lines>...
divine-core-1 | limits=limits,
divine-core-1 | )
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpx/_transports/default.py", line 294, in __init__
divine-core-1 | import httpcore
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpcore/__init__.py", line 140, in <module>
divine-core-1 | setattr(__locals[__name], "__module__", "httpcore") # noqa
divine-core-1 | ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
divine-core-1 | AttributeError: 'typing.Union' object has no attribute '__module__' and no __dict__ for setting new attributes. Did you mean: '__reduce__'?
Issue Analysis
The problem occurs in the httpcore package (a dependency of httpx) in its init.py file (around line 140). The code attempts to set the module attribute on all exported names:
7112109dc9 failed: 'typing.Union' object has no attribute '__module__' and no __dict__ for setting new attributes
divine-core-1 | Traceback (most recent call last):
divine-core-1 | File "/app/divine/divine/networking/core.py", line 71, in request
divine-core-1 | async with httpx.AsyncClient(http2=True, verify=TLS_CONTEXT_HTTP2) as session:
divine-core-1 | ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpx/_client.py", line 1402, in __init__
divine-core-1 | self._transport = self._init_transport(
divine-core-1 | ~~~~~~~~~~~~~~~~~~~~^
divine-core-1 | verify=verify,
divine-core-1 | ^^^^^^^^^^^^^^
divine-core-1 | ...<5 lines>...
divine-core-1 | transport=transport,
divine-core-1 | ^^^^^^^^^^^^^^^^^^^^
divine-core-1 | )
divine-core-1 | ^
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpx/_client.py", line 1445, in _init_transport
divine-core-1 | return AsyncHTTPTransport(
divine-core-1 | verify=verify,
divine-core-1 | ...<4 lines>...
divine-core-1 | limits=limits,
divine-core-1 | )
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpx/_transports/default.py", line 294, in __init__
divine-core-1 | import httpcore
divine-core-1 | File "/usr/local/lib/python3.14t/site-packages/httpcore/__init__.py", line 140, in <module>
divine-core-1 | setattr(__locals[__name], "__module__", "httpcore") # noqa
divine-core-1 | ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
divine-core-1 | AttributeError: 'typing.Union' object has no attribute '__module__' and no __dict__ for setting new attributes. Did you mean: '__reduce__'?
In Python 3.14, typing.Union objects can be included in the module namespace, but they don't have a module attribute and don't support setting attributes (no dict).
Environment
- Python 3.14.0 alpha 6 and alpha 7
- httpx 0.28.1
- httpcore 1.0.7
Steps to Reproduce
- Install Python 3.14.0 (alpha 6 or 7)
- Install httpx 0.28.1
- Try to use httpx.AsyncClient with http2=True
Suggested Fix
The httpcore module should check if the object supports attribute setting before attempting to set the module attribute. Something like:
__locals = locals()
for __name in __all__:
if not __name.startswith("__"):
setattr(__locals[__name], "__module__", "httpcore") # noqa
This should be a relatively simple fix that maintains backward compatibility with older Python versions while supporting Python 3.14.
Metadata
Metadata
Assignees
Labels
No labels