Repository navigation
Python 3.15: Lazy imports break httpx. #3807
Replies: 2 comments 1 reply
|
The failing code is in httpcore rather than httpx. httpx imports httpcore inside __locals = locals()
for __name in __all__:
if not __name.startswith(("__", "SOCKET_OPTION")):
setattr(__locals[__name], "__module__", "httpcore")A plain dict lookup returns the placeholder, so Reproduced on the
Until httpcore changes, a lazy imports filter that keeps httpcore's own imports eager works around it. import sys
sys.set_lazy_imports_filter(lambda importer, name, fromlist=None: importer != "httpcore")With that set before httpx is used, In httpcore itself, reading the names as module attributes instead of from the import sys as __sys
__module = __sys.modules[__name__]
for __name in __all__:
# Exclude SOCKET_OPTION, it causes AttributeError on Python 3.14
if not __name.startswith(("__", "SOCKET_OPTION")):
setattr(getattr(__module, __name), "__module__", "httpcore") # noqaWith that change the same sync and async requests return 200 under |
|
The change is now on a branch with a regression test and a CHANGELOG line: kasparovabi/httpcore@7042264 ( Opening a pull request on encode/httpcore is currently limited to collaborators, so I am leaving it here in case a maintainer wants to pick it up. |
Uh oh!
There was an error while loading. Please reload this page.
If you enable
-X lazy_imports=alladded in python 3.15 the setattr block inhttpx/__init__.pybreaks.All reactions