Skip to content

reject boolean port values in URL.build#1768

Draft
HrachShah wants to merge 2 commits into
aio-libs:masterfrom
HrachShah:fix/build-reject-bool-port
Draft

reject boolean port values in URL.build#1768
HrachShah wants to merge 2 commits into
aio-libs:masterfrom
HrachShah:fix/build-reject-bool-port

Conversation

@HrachShah

Copy link
Copy Markdown

What do these changes do?

Reject boolean values for the port argument of URL.build() at the call site
with a clear TypeError, matching the existing validation in URL.with_port().

Are there changes in behavior for the user?

yes. Previously, calling URL.build(scheme="http", host="example.com", port=True)
silently slipped past the not isinstance(port, int) check (because bool is a
subclass of int) and the constructor later raised a confusing
ValueError: Invalid URL: port can't be converted to integer from the IP literal
parsing path. Now it raises TypeError: The port is required to be int, got <class 'bool'>.
from the same URL.build argument-validation block where float/str/bytes are
already rejected.

Is it a substantial burden for the maintainers to support this?

no. The check mirrors the one already in URL.with_port (line ~1189) so the
cost is one extra isinstance(port, bool) per URL.build call.

Related issue number

none

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

Drafted with code from HrachShah; reviewed by HrachShah.

Agent run details (optional, for reviewers)

Tests: PYTHONPATH=. python3 -m pytest tests/test_url.py tests/test_update_query.py tests/test_pickle.py tests/test_normalize_path.py tests/test_cached_property.py tests/test_cache.py tests/test_pydantic.py tests/test_quoting_benchmarks.py --override-ini="addopts=" → 645 passed, 10 skipped (test_quoting.py is excluded because the Cython quoter is not compiled in this environment).
Lint: make doc-spelling cannot run here because pyenchant needs the enchant C library; the fragment only uses words already in docs/spelling_wordlist.txt (bool, booleans, bools, yarl) plus standard English.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jun 25, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 25, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 9.52%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 96 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_url_build_encoded_with_host_and_port 254.4 µs 281.2 µs -9.52%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing HrachShah:fix/build-reject-bool-port (2ecfb7b) with master (315a7aa)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (b0d27e4) during the generation of this report, so 315a7aa was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.86%. Comparing base (60d4d7d) to head (2ecfb7b).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1768   +/-   ##
=======================================
  Coverage   99.86%   99.86%           
=======================================
  Files          21       21           
  Lines        4310     4314    +4     
  Branches      252      252           
=======================================
+ Hits         4304     4308    +4     
  Misses          4        4           
  Partials        2        2           
Flag Coverage Δ
CI-GHA 99.79% <100.00%> (+<0.01%) ⬆️
OS-Linux 99.79% <100.00%> (+<0.01%) ⬆️
OS-Windows 98.53% <100.00%> (+<0.01%) ⬆️
OS-macOS 98.72% <100.00%> (+<0.01%) ⬆️
Py-3.10 99.69% <100.00%> (+<0.01%) ⬆️
Py-3.11 99.69% <100.00%> (+<0.01%) ⬆️
Py-3.12 99.69% <100.00%> (+<0.01%) ⬆️
Py-3.13 99.74% <100.00%> (+<0.01%) ⬆️
Py-3.14 99.74% <100.00%> (+<0.01%) ⬆️
Py-3.14t 99.74% <100.00%> (+<0.01%) ⬆️
Py-pypy-3.11 99.37% <100.00%> (+<0.01%) ⬆️
VM-macos-latest 98.72% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 99.79% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 98.53% <100.00%> (+<0.01%) ⬆️
pytest 99.79% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28207936576

Coverage decreased (-0.03%) to 98.71%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (6 of 8 lines covered, 75.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
tests/test_url.py 7 5 71.43%
Total (2 files) 8 6 75.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 6217
Covered Lines: 6136
Line Coverage: 98.7%
Relevant Branches: 61
Covered Branches: 61
Branch Coverage: 100.0%
Branches in Coverage %: Yes
Coverage Strength: 0.99 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants