GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-149746: Handle CIDRs in NO_PROXY env var by turettn · Pull Request #156336 · python/cpython

Conversation

@turettn

@turettn turettn commented Aug 24, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

The change

This PR allows IPv4 & IPv6 CIDRs to be specified in NO_PROXY. This is a fairly common convention, as described in #149746.

With this change, if the following env var is set:

NO_PROXY=192.168.0.0/16

the proxy will not be used for any IP address in that range (e.g. 192.168.4.4).

Caching

Since parsing NO_PROXY involves a non-trivial amount of string manipulation, object allocation, and attempts to parse, it turned out significantly more expensive for long NO_PROXY strings than I expected. Since I would expect the environment to change very infrequently, I added a lru_cache around the repeated parsing of the same NO_PROXY string. In the overwhelming majority of production instances, I would expect the size of the cache to sit at 1, and the number of cache hits to be high (e.g. one per request).

Tightly coupled bug

Along the way, I discovered a bug in urllib.parse.splitport, which is deprecated but still used heavily internally:

>>> urllib.parse.splitport('::1')
<python-input-4>:1: DeprecationWarning: urllib.parse.splitport() is deprecated as of 3.8, use urllib.parse.urlparse() instead
(':', '1')

I tried to work around this issue throughout my PR, but it kept getting uglier and I decided to bundle the fix with this change together. If you'd like a different approach (e.g. 2 stacked PRs) just let me know and I'm happy to refactor.

Existing Issue & PR

I foolishly wrote this PR before looking for existing issues (it started as a monkey-patch to fix an urgent issue in prod). When I found the issue, I also found an existing PR #149744.

The big difference in our approach seems to be that I focused solely on the environment variable, and not on environment-specific settings. It seems like Windows doesn't support CIDRs in the registry value, and I couldn't find a clear indicator that MacOS supports it either.

I went back and forth about posting this, but figured if its not helpful the close button is right there :).

Final notes

This is my first attempt to upstream code to Python. If I missed anything important or violated convention somewhere along the way, please let me know - I'm happy to amend my PR as needed.

  • Issue: CIDR support for proxy bypass list #149746

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Accurio reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@turettn
pythongh-149746: Handle CIDRs in NO_PROXY env var
6e5aea6
@python-cla-bot

python-cla-bot Bot commented Aug 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Aug 24, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting review label Aug 24, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 24, 2026
CIDR support for proxy bypass list #149746
Open
@read-the-docs-community

read-the-docs-community Bot commented Aug 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34215229 | 📁 Comparing 46818b2 against main (ee521e8)

  🔍 Preview build  

2 files changed
± library/urllib.request.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

turettn added 3 commits August 24, 2026 16:32
@turettn
add blurb
7619936
@turettn
lint
01b1e57
@turettn
backticks
46818b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@turettn
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.