Compatibility with 3.15 lazy imports #1106
Replies: 1 comment
|
This is a compatibility bug in httpcore's public-name cleanup, not in A caller-side workaround is to import httpcore eagerly, then restore lazy mode: import sys
sys.set_lazy_imports("normal")
import httpcore
sys.set_lazy_imports("all")
print(httpcore.ConnectionPool)A small cross-version library fix would skip the cosmetic import types
lazy_import_type = getattr(types, "LazyImportType", None)
__locals = locals()
for __name in __all__:
if __name.startswith(("__", "SOCKET_OPTION")):
continue
value = __locals[__name]
if lazy_import_type is not None and isinstance(value, lazy_import_type):
continue
setattr(value, "__module__", "httpcore")The failing loop is visible in httpcore/init.py. Skipping the rewrite only leaves the original implementation module in introspection output; it does not change the exported object. Python 3.15 documents |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey folks. I was just testing the Sentry SDK on a Python 3.15 beta (
3.15.0b3) -- we use httpcore in our experimental HTTP2 transport -- and ran into a possible problem when httpcore is used with lazy imports.The problem, distilled, can be triggered as follows:
repro.py:PYTHON_LAZY_IMPORTS=all uv run repro.pyYou'll get this stacktrace:
Thought I'd raise this with y'all as a heads up if you think this is actionable and httpcore should work with
PYTHON_LAZY_IMPORTS=all(which is not a given).All reactions