Skip to content

Replace vendored mureq with stdlib urllib.request#362

Open
anyasabo wants to merge 1 commit into
RobertCraigie:mainfrom
anyasabo:anya/replace-mureq-with-urllib
Open

Replace vendored mureq with stdlib urllib.request#362
anyasabo wants to merge 1 commit into
RobertCraigie:mainfrom
anyasabo:anya/replace-mureq-with-urllib

Conversation

@anyasabo
Copy link
Copy Markdown

@anyasabo anyasabo commented Jun 2, 2026

While using pyright in an environment with an HTTP proxy, I noticed that we were failing version checks. mureq ignores any proxy configuration, but urllib does not. This switches to urllib and confirmed that this now works when there is an egress proxy, and is net less lines of code.

In the meantime, it is possible to disable version warnings but I think this is preferable.

clanker generated below


Summary

  • Removes the vendored mureq library (~395 lines) and replaces all HTTP calls with Python's stdlib urllib.request.urlopen
  • mureq uses raw http.client connections that bypass HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables, causing timeouts in proxied environments (corporate networks, CI behind firewalls, etc.)
  • urllib.request respects proxy env vars out of the box via its default ProxyHandler — no new dependencies needed

Motivation

In environments with an HTTPS-intercepting proxy (common in enterprise setups), pyright-python's version check and Pylance metadata fetch hang indefinitely because mureq opens direct TCP connections that never reach the target host. The 1-second timeout mitigates this for the version check, but download_pyright.py uses the default 15-second timeout and blocks noticeably.

Python's urllib.request has handled proxies correctly since Python 3.0. Since pyright-python only uses mureq for simple GET requests + JSON parsing, the stdlib is a direct replacement with zero behavioral change (aside from now working behind proxies).

Changes

  • src/pyright/utils.py — PyPI latest-version check
  • src/pyright/_utils.py — Pylance release metadata fetch
  • scripts/download_pyright.py — npm registry query + tarball download
  • src/pyright/_mureq.py — deleted
  • pyproject.toml — removed _mureq.py from ruff/pyright exclude lists

Test plan

  • Verified imports load cleanly
  • Verified get_latest_version() returns correct version from PyPI
  • Verified pyright --version completes full flow (version check + npm install) through an HTTPS proxy
  • ruff check passes

mureq uses raw http.client connections that bypass HTTP_PROXY/HTTPS_PROXY
environment variables, causing timeouts in proxied environments. Python's
urllib.request.urlopen respects proxy env vars out of the box via its
default ProxyHandler, making this a drop-in fix with no new dependencies.
@anyasabo anyasabo marked this pull request as ready for review June 2, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant