Skip to content

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

@atemate

Description

@atemate

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".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions