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

Why can't URL.build() accept a non-empty scheme with an empty host? #464

Closed
atemate opened this issue Jun 10, 2020 · 1 comment · Fixed by #479
Closed

Why can't URL.build() accept a non-empty scheme with an empty host? #464

atemate opened this issue Jun 10, 2020 · 1 comment · Fixed by #479

Comments

@atemate
Copy link

atemate commented Jun 10, 2020

Why does URL.build has this check:

yarl/yarl/__init__.py

Lines 201 to 202 in 5ef628f

if not host and scheme:
raise ValueError('Can\'t build URL with "scheme" but without "host".')

From my perspective, URL with a scheme and without a host is valid:

In [12]: u = URL("scheme://")                                                                                                                                                                 

In [13]: u.scheme, u.host                                                                                                                                                                     
Out[13]: ('scheme', None)

In [14]: URL.build(scheme=u.scheme, host=u.host)                                                                                                                                              
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-c54f9b7a765d> in <module>
----> 1 URL.build(scheme=u.scheme, host=u.host)
...
    200 
    201         if not host and scheme:
--> 202             raise ValueError('Can\'t build URL with "scheme" but without "host".')
    203         if port and not host:
    204             raise ValueError('Can\'t build URL with "port" but without "host".')

ValueError: Can't build URL with "scheme" but without "host".
@asvetlov
Copy link
Member

Oversight, probably.
Plus, relaxing the rule is much easier from backward-compatibility point of view than the restricting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants