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

URL.build(): Raise TypeError if host argument is None #809

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/808.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made :py:meth:`URL.build` raise a :py:exc:`TypeError` if the ``host`` argument is :py:data:`None` — by :user:`paulpapacz`.
5 changes: 5 additions & 0 deletions tests/test_url_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ def test_build_with_authority_with_path_without_leading_slash():
URL.build(scheme="http", host="example.com", path="path_without_leading_slash")


def test_build_with_none_host():
with pytest.raises(TypeError, match="NoneType is illegal for.*host"):
URL.build(scheme="http", host=None)


def test_build_with_none_path():
with pytest.raises(TypeError):
URL.build(scheme="http", host="example.com", path=None)
Expand Down
3 changes: 2 additions & 1 deletion yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ def build(
if (
scheme is None
or authority is None
or host is None
or path is None
or query_string is None
or fragment is None
):
raise TypeError(
'NoneType is illegal for "scheme", "authority", "path", '
'NoneType is illegal for "scheme", "authority", "host", "path", '
'"query_string", and "fragment" args, use empty string instead.'
)

Expand Down