From ea970f2e388dc071ac118b8fb9c4ed653fa8499a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 20 Oct 2024 22:19:13 -1000 Subject: [PATCH] Remove unreachable authority absolute path check in `URL.__new__` (#1368) --- yarl/_url.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/yarl/_url.py b/yarl/_url.py index 0e3677e54..78f22e927 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -121,12 +121,6 @@ def rewrite_module(obj: _T) -> _T: return obj -def _raise_for_authority_missing_abs_path() -> None: - """Raise when he path in URL with authority starts lacks a leading slash.""" - msg = "Path in a URL with authority should start with a slash ('/') if set" - raise ValueError(msg) - - @rewrite_module class URL: # Don't derive from str @@ -270,8 +264,6 @@ def __new__( if netloc: if "." in path: path = normalize_path(path) - if path[0] != "/": - _raise_for_authority_missing_abs_path() query = QUERY_REQUOTER(query) if query else query fragment = FRAGMENT_REQUOTER(fragment) if fragment else fragment @@ -376,7 +368,11 @@ def build( if "." in path: path = normalize_path(path) if path[0] != "/": - _raise_for_authority_missing_abs_path() + msg = ( + "Path in a URL with authority should " + "start with a slash ('/') if set" + ) + raise ValueError(msg) query_string = QUERY_QUOTER(query_string) if query_string else query_string fragment = FRAGMENT_QUOTER(fragment) if fragment else fragment