From c7ab1db0ee00a64a75bbecbfea9b754593a4f14c Mon Sep 17 00:00:00 2001 From: Thanos <111999343+Sachaa-Thanasius@users.noreply.github.com> Date: Fri, 14 Jun 2024 23:02:49 -0400 Subject: [PATCH] Annotate `misc.get_path()` while breaking an import cycle. - `uri` can't be eagerly imported within `misc` without causing a circular import, but is necessary for getting the most currently correct parameter type. --- src/rfc3986/misc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rfc3986/misc.py b/src/rfc3986/misc.py index 7cbbbec..5e0d925 100644 --- a/src/rfc3986/misc.py +++ b/src/rfc3986/misc.py @@ -18,9 +18,14 @@ expressions for parsing and validating URIs and their components. """ import re +import typing as t from . import abnf_regexp +if t.TYPE_CHECKING: + # Break an import loop. + from . import uri + # These are enumerated for the named tuple used as a superclass of # URIReference URI_COMPONENTS = ["scheme", "authority", "path", "query", "fragment"] @@ -118,7 +123,7 @@ # Path merger as defined in http://tools.ietf.org/html/rfc3986#section-5.2.3 -def merge_paths(base_uri, relative_path): +def merge_paths(base_uri: "uri.URIReference", relative_path: str) -> str: """Merge a base URI's path with a relative URI's path.""" if base_uri.path is None and base_uri.authority is not None: return "/" + relative_path