URL.build: reject boolean port values#1772
Conversation
for more information, see https://pre-commit.ci
Merging this PR will degrade performance by 9.84%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_url_build_encoded_with_host_and_port |
254.4 µs | 282.1 µs | -9.84% |
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/url-build-reject-bool-port (6e0388a) with master (95ffe17)
The bool-rejecting fix in URL.build rewrote the port guard to raise 'port should be int or None, got <type>' instead of 'The port is required to be int, got <type>'. The pre-existing port-str parameter case in test_build_with_port still matched the old text, so a URL.build(port='') invocation raised the new message and the test failed at the regex check. Update the test to match the new message shape. The new test_build_rejects_non_int_port already covers the bool, str, and float cases introduced by the same source change.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1772 +/- ##
=======================================
Coverage 99.86% 99.86%
=======================================
Files 21 21
Lines 4310 4319 +9
Branches 252 252
=======================================
+ Hits 4304 4313 +9
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:
|
What do these changes do?
Reject boolean port values in
URL.build(port=...)with a clearTypeErrorat the call site, matching the behaviour ofURL.with_port. The previousisinstance(port, int)guard acceptedTrueandFalsebecauseboolis a subclass ofint; the bool then flowed intomake_netlocand surfaced asValueError: Invalid URL: port can't be converted to integerfrom inside the netloc assembly one frame deeper than the call site, with the wrong exception type.Are there changes in behavior for the user?
Yes.
URL.build(port=True)andURL.build(port=False)now raiseTypeErrorat the call site instead of leaking a confusingValueErrorfrom deeper in the netloc assembly. Realintports andport=Noneare unaffected; onlyTrueandFalsechange behaviour, and they were never producing a meaningful URL before.Is it a substantial burden for the maintainers to support this?
No. The fix is two lines in one function. A regression test (
test_build_rejects_non_int_port) is included that fails on the original guard and passes with the fix.Related issue number
None.
Checklist
CONTRIBUTORS.txtCHANGES/folderDrafted with MiniMax M3; reviewed by keenrose.