[HTTPXodus] migrate httpx to httpx2 (hard switch; closes #5258) - #5351
ProgrammerPlus1998 wants to merge 4 commits into
Conversation
Adopt the actively maintained httpx2 (Pydantic Services fork, with original
httpx author Tom Christie involved) alongside the existing httpx pin. The
dual import keeps every downstream user's import path unchanged and avoids
a hard breaking change for code that type-annotates against httpx.Proxy /
httpx.URL / httpx.Timeout in the public ApplicationBuilder surface.
- pyproject.toml: add httpx2 >= 2.12.0 (python_version >= '3.10') alongside
the existing httpx >=0.27,<0.29 pin. PTB already requires python >=3.10,
so the marker is documentation, not a constraint.
- src/telegram/request/_httpxrequest.py and
src/telegram/ext/_applicationbuilder.py: dual import that prefers
httpx2 and falls back to httpx on ModuleNotFoundError, matching the
pattern used by the other HTTPXodus migrations (AutoGPT, mem0, Starlette).
- tests/{auxil/networking.py,ext/test_applicationbuilder.py,request/test_request.py,
test_bot.py,test_official/scraper.py}: same dual import so test
side-effects and isinstance checks resolve to the same module the SUT
imports.
Refs: python-telegram-bot#5258
6c83b97 to
0775a55
Compare
fb3f1d6 to
ea47457
Compare
Repair syntactically broken import shims left in _httpxrequest.py, _applicationbuilder.py and four test files; rename remaining bare 'httpx' monkeypatch targets; switch the http2/socks extras to httpx2[...]; drop the obsolete httpcore pin (httpx2 uses httpcore2); replace dead python-httpx2.org links; re-lock (adds httpx2's missing truststore/httpx2-jsfetch deps). Refs: python-telegram-bot#5258
| import httpx | ||
| try: | ||
| import httpx2 | ||
| except ModuleNotFoundError: |
There was a problem hiding this comment.
This seems...wrong? The indentation is off and the except does not have any block. Also I would expect it to be either a plain import of httpx2, or have a fallback like
...
except ModuleNotFoundError:
import httpx as httpx2 # or vice versa|
You're absolutely right — that hunk was a broken leftover from the earlier dual-import revision, and it was worse than it looked: six files had mangled Fixed in 579d823: it's now exactly what you expected — a plain |
|
Not looking for slop / unprompted PRs |
Closes #5258
What this PR does
Complete hard switch from
httpxtohttpx2:import httpx2intelegram/request/_httpxrequest.pyandtelegram/ext/_applicationbuilder.py— notry/exceptdual-import, no aliasinghttpx.Xreferences updated tohttpx2.X, including test monkeypatch targets (monkeypatch.setattr(httpx2, ...))pyproject.toml:httpx2>=2.12.0unconditional (requires-pythonis already>=3.10);http2/socksextras now pullhttpx2[http2]/httpx2[socks]; thehttpcore>=1.0.9workaround pin is dropped (httpx2 depends onhttpcore2, which pins correctly)uv.lockregenerated (adds httpx2's own dependencies — truststore, httpx2-jsfetch — which were missing)Diff summary
pyproject.tomlhttpx2>=2.12.0unconditioned; extras switched tohttpx2[...]; drophttpcorepinsrc/telegram/request/_httpxrequest.pyimport httpx2;httpx2.Xthroughout; doc links fixedsrc/telegram/ext/_applicationbuilder.pytests/request/test_request.py,tests/ext/test_applicationbuilder.py,tests/test_bot.py,tests/test_official/scraper.pyimport httpx2; monkeypatch targets renamedtests/auxil/networking.pyfrom httpx2 import AsyncClient, AsyncHTTPTransport, Responseuv.lockThe string-matching against
"httpx[http2]"/"httpx[socks]"in_httpxrequest.pyis intentionally kept: httpx2 2.12.0 still emits those exact messages when the extras are missing.Test results
Full suite (
pytest tests,-n auto, per-test timeout 120s), httpx2 2.12.0:TestUpdater/TestApplicationwebhook tests time out — also time out on the base commit with real httpx in the same environment (verified by control run); local webhook harness issue on this machineUser_personal_channel_missing,Bot_score_not_modified, andtest_get_chat— the public test bot's profile currently shows vandalized text)tests/request/test_request.py+tests/ext/test_applicationbuilder.py— 229 passed, 2 skipped, 5 xfailedNotes for reviewer
httpx2verifies TLS against the OS trust store (viatruststore) instead of the bundledcertifi. Deployments that relied on certifi's CA bundle (minimal containers, corporate proxies) may needSSL_CERT_FILE/SSL_CERT_DIRafter the switch. Worth a line in the changelog.Happy to revise per review — and equally happy to close this PR if the maintainers would rather wait for
httpx1.0 stable. 🙏