Cache recent URL parse results

KL
1mo ago
+25-0

Summary

Cache the 128 most recent plain string URLs parsed without keyword overrides. Repeated requests to the same URL can reuse the immutable parse result instead of repeating validation and normalization. Calls with keyword overrides or string subclasses use the original parsing path, preserving validation and support for unhashable subclasses.

The cache retains up to 128 raw URL strings, including any credentials in those URLs, until eviction or process exit.

Tests

  • uv run pytest -q tests/httpx2 (1755 passed, 1 skipped)
  • uv run ruff check src/httpx2/httpx2/_urlparse.py tests/httpx2/models/test_url.py
  • uv run ruff format --check src/httpx2/httpx2/_urlparse.py tests/httpx2/models/test_url.py
  • uv run mypy src/httpx2/httpx2/_urlparse.py tests/httpx2/models/test_url.py

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.