Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise TypeError when a string is passed for port to URL.build() #959

Merged
merged 16 commits into from
Nov 28, 2023

Conversation

commonism
Copy link
Contributor

@commonism commonism commented Nov 21, 2023

What do these changes do?

Using port="" resulted in malformed urls, now using string for port raises TypeError

Are there changes in behavior for the user?

URL.build does not accept strings as port any longer.
URL.build does not create invalid urls when using "" as value for port.

Related issue number

fix #883

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: Fix issue with non-ascii contents in doctest text files.

@commonism
Copy link
Contributor Author

I did not include this in the PR - but the requirements file has a typo.

diff --git a/requirements/dev.txt b/requirements/dev.txt
index 62fe39a..3b676e4 100644
--- a/requirements/dev.txt
+++ b/requirements/dev.txt
@@ -1,2 +1,2 @@
--r text.txt
+-r test.txt
 towncrier==23.11.0

@webknjaz
Copy link
Member

I did not include this in the PR - but the requirements file has a typo.

diff --git a/requirements/dev.txt b/requirements/dev.txt
index 62fe39a..3b676e4 100644
--- a/requirements/dev.txt
+++ b/requirements/dev.txt
@@ -1,2 +1,2 @@
--r text.txt
+-r test.txt
 towncrier==23.11.0

Fixed that in 85b53c9. Thanks!

yarl/_url.py Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
CHANGES/883.bugfix Outdated Show resolved Hide resolved
Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually… I'm not sure if it's a good idea to accept empty strings at all. Should we error out instead, and aim for stricter public API input validation in general?

cc @Dreamsorcerer @mjpieters

@Dreamsorcerer
Copy link
Member

Dreamsorcerer commented Nov 21, 2023

Actually… I'm not sure if it's a good idea to accept empty strings at all. Should we error out instead, and aim for stricter public API input validation in general?

Yeah, it's typed as int. I'm not sure we should add code that explicitly supports something the type checker rejects (and supporting str in general would be odd).

port: Optional[int] = ...,

commonism and others added 3 commits November 22, 2023 09:00
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
yarl/_url.py Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8d28329) 99.74% compared to head (40b9ddb) 99.33%.
Report is 55 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #959      +/-   ##
==========================================
- Coverage   99.74%   99.33%   -0.41%     
==========================================
  Files           4       17      +13     
  Lines         772     3317    +2545     
  Branches      219      325     +106     
==========================================
+ Hits          770     3295    +2525     
- Misses          2       22      +20     
Flag Coverage Δ
CI-GHA 99.24% <100.00%> (?)
OS-Linux 99.24% <100.00%> (?)
OS-Windows 99.57% <100.00%> (?)
OS-macOS 99.00% <100.00%> (?)
Py-3.10.11 99.48% <100.00%> (?)
Py-3.10.13 99.12% <100.00%> (?)
Py-3.11.6 99.12% <100.00%> (?)
Py-3.12.0 99.12% <100.00%> (?)
Py-3.7.17 99.04% <100.00%> (?)
Py-3.7.9 99.46% <100.00%> (?)
Py-3.8.10 99.41% <100.00%> (?)
Py-3.8.18 99.06% <100.00%> (?)
Py-3.9.13 99.41% <100.00%> (?)
Py-3.9.18 99.06% <100.00%> (?)
Py-pypy7.3.11 99.38% <100.00%> (?)
Py-pypy7.3.13 99.38% <100.00%> (?)
VM-macos 99.00% <100.00%> (?)
VM-ubuntu 99.24% <100.00%> (?)
VM-windows 99.57% <100.00%> (?)
unit ?

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

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

CHANGES/883.bugfix Outdated Show resolved Hide resolved
CHANGES/883.bugfix Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
yarl/_url.py Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

@commonism looks like the PR title and description no longer correspond to its contents. This needs to be corrected.

commonism and others added 2 commits November 24, 2023 06:22
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@commonism commonism changed the title URL.build - port can be "" URL.build - raise TypeError when a string value is passed as the port argument Nov 24, 2023
tests/test_url_build.py Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
tests/test_url_build.py Outdated Show resolved Hide resolved
@webknjaz webknjaz changed the title URL.build - raise TypeError when a string value is passed as the port argument Raise TypeError when a string is passed for port to URL.build() Nov 28, 2023
@webknjaz webknjaz merged commit b3a5a71 into aio-libs:master Nov 28, 2023
47 of 49 checks passed
@commonism commonism deleted the port branch November 29, 2023 07:45
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.

regression in URL.build(…,port="")
3 participants