Skip to content

Add Python 3.16 support - #111

Merged
kovidgoyal merged 1 commit into
python-mechanize:masterfrom
rosset:master
Dec 3, 2026
Merged

kovidgoyal merged 1 commit into
python-mechanize:masterfrom
rosset:master

Conversation

@rosset

@rosset rosset commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Metadata/CI:

  • pyproject.toml: add 'Programming Language :: Python :: 3.16' classifier
  • .github/workflows/ci.yml: add 3.16 to linux matrix; bump other-matrix max from 3.15 to 3.16

Source fixes for two 3.16 stdlib behavior changes (verified on 3.16.0a2):

  1. urllib.parse now validates ports eagerly at urlsplit()/urlparse() time, raising ValueError for non-integer ports (e.g. ':bad') instead of deferring to the .port property. gh-88037, listed under 'Porting to Python 3.16' in the 3.16 What's New.

    Three call sites in _urllib2_fork.py are wrapped in try/except ValueError:

    • _url_origin(): return the URL as its own origin
    • normalize_url(): return the URL unchanged
    • request_host(): fall back to the Host header
  2. http.cookiejar.MozillaCookieJar.save() now writes '0' (not '') in the expires field for session cookies, matching curl/Wget convention. gh-61366.

    _clientcookie.py _really_load() now treats expires == '0' the same as the empty string: session cookie (expires=None, discard=True).

All 346 tests pass on 3.10-3.16. ruff clean.

Metadata/CI:
- pyproject.toml: add 'Programming Language :: Python :: 3.16' classifier
- .github/workflows/ci.yml: add 3.16 to linux matrix; bump other-matrix
  max from 3.15 to 3.16

Source fixes for two 3.16 stdlib behavior changes (verified on 3.16.0a2):

1. urllib.parse now validates ports eagerly at urlsplit()/urlparse()
   time, raising ValueError for non-integer ports (e.g. ':bad')
   instead of deferring to the .port property.  gh-88037, listed under
   'Porting to Python 3.16' in the 3.16 What's New.

   Three call sites in _urllib2_fork.py are wrapped in try/except
   ValueError:
   - _url_origin(): return the URL as its own origin
   - normalize_url(): return the URL unchanged
   - request_host(): fall back to the Host header

2. http.cookiejar.MozillaCookieJar.save() now writes '0' (not '')
   in the expires field for session cookies, matching curl/Wget
   convention.  gh-61366.

   _clientcookie.py _really_load() now treats expires == '0' the same
   as the empty string: session cookie (expires=None, discard=True).

All 346 tests pass on 3.10-3.16. ruff clean.

Signed-off-by: Filipe Rosset <rosset.filipe@gmail.com>
@kovidgoyal
kovidgoyal merged commit c170c26 into python-mechanize:master Dec 3, 2026
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.

2 participants