Skip to content

Commit

Permalink
URL.build(): Raise TypeError if host argument is None (#809)
Browse files Browse the repository at this point in the history
* `URL.build()`: Raise `TypeError` if `host` argument is `None`

* Update CHANGES/808.bugfix.rst

Co-authored-by: Sviatoslav Sydorenko <[email protected]>

Co-authored-by: Sam Bull <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2023
1 parent ca96858 commit 89cc6b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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

0 comments on commit 89cc6b0

Please sign in to comment.