Replace vendored mureq with stdlib urllib.request#362
Open
anyasabo wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
mureqlibrary (~395 lines) and replaces all HTTP calls with Python's stdliburllib.request.urlopenmurequses rawhttp.clientconnections that bypassHTTP_PROXY/HTTPS_PROXY/NO_PROXYenvironment variables, causing timeouts in proxied environments (corporate networks, CI behind firewalls, etc.)urllib.requestrespects proxy env vars out of the box via its defaultProxyHandler— no new dependencies neededMotivation
In environments with an HTTPS-intercepting proxy (common in enterprise setups), pyright-python's version check and Pylance metadata fetch hang indefinitely because
mureqopens direct TCP connections that never reach the target host. The 1-second timeout mitigates this for the version check, butdownload_pyright.pyuses the default 15-second timeout and blocks noticeably.Python's
urllib.requesthas handled proxies correctly since Python 3.0. Since pyright-python only usesmureqfor 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 checksrc/pyright/_utils.py— Pylance release metadata fetchscripts/download_pyright.py— npm registry query + tarball downloadsrc/pyright/_mureq.py— deletedpyproject.toml— removed_mureq.pyfrom ruff/pyright exclude listsTest plan
get_latest_version()returns correct version from PyPIpyright --versioncompletes full flow (version check + npm install) through an HTTPS proxyruff checkpasses