reject boolean port values in URL.build#1768
Conversation
for more information, see https://pre-commit.ci
Merging this PR will degrade performance by 9.52%
|
| 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
Footnotes
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Coverage Report for CI Build 28207936576Coverage decreased (-0.03%) to 98.71%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
What do these changes do?
Reject boolean values for the
portargument ofURL.build()at the call sitewith a clear
TypeError, matching the existing validation inURL.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 (becauseboolis asubclass of
int) and the constructor later raised a confusingValueError: Invalid URL: port can't be converted to integerfrom the IP literalparsing path. Now it raises
TypeError: The port is required to be int, got <class 'bool'>.from the same
URL.buildargument-validation block where float/str/bytes arealready 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 thecost is one extra
isinstance(port, bool)perURL.buildcall.Related issue number
none
Checklist
CONTRIBUTORS.txtCHANGES/folderDrafted 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-spellingcannot run here becausepyenchantneeds theenchantC library; the fragment only uses words already indocs/spelling_wordlist.txt(bool, booleans, bools, yarl) plus standard English.