From f3ca9f1254027cec1a49051b8de8f1a2eb5aadad Mon Sep 17 00:00:00 2001 From: Roman Tolkachyov Date: Mon, 26 Jan 2026 00:23:38 +0300 Subject: [PATCH 1/2] Improve python typings for PyCharm --- urlpattern.pyi | 52 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/urlpattern.pyi b/urlpattern.pyi index 1e2e266..811ba31 100644 --- a/urlpattern.pyi +++ b/urlpattern.pyi @@ -1,25 +1,55 @@ from typing_extensions import TypeAlias, TypedDict, overload -URLPatternInput: TypeAlias = str | URLPatternInit class URLPatternOptions(TypedDict, total=False): ignoreCase: bool + +class URLPatternInit(TypedDict, total=False): + protocol: str + username: str + password: str + hostname: str + port: str + pathname: str + search: str + hash: str + baseURL: str + class URLPattern: @overload def __init__( self, - input: URLPatternInput, + input: URLPatternInit, baseURL: str, options: URLPatternOptions | None = None, ): ... @overload def __init__( - self, input: URLPatternInput, options: URLPatternOptions | None = None + self, + input: str, + baseURL: str, + options: URLPatternOptions | None = None, ): ... - def test(self, input: URLPatternInput = {}, baseURL: str | None = None) -> bool: ... + @overload + def __init__( + self, input: URLPatternInit, options: URLPatternOptions | None = None + ): ... + @overload + def __init__( + self, input: str, options: URLPatternOptions | None = None + ): ... + @overload + def test(self, input: URLPatternInit, baseURL: str | None = None) -> bool: ... + @overload + def test(self, input: str, baseURL: str | None = None) -> bool: ... + @overload def exec( - self, input: URLPatternInput = {}, baseURL: str | None = None + self, input: URLPatternInit, baseURL: str | None = None + ) -> URLPatternResult | None: ... + @overload + def exec( + self, input: str, baseURL: str | None = None ) -> URLPatternResult | None: ... @property def protocol(self) -> str: ... @@ -38,19 +68,9 @@ class URLPattern: @property def hash(self) -> str: ... -class URLPatternInit(TypedDict, total=False): - protocol: str - username: str - password: str - hostname: str - port: str - pathname: str - search: str - hash: str - baseURL: str class URLPatternResult(TypedDict): - inputs: list[URLPatternInput] + inputs: list[str | URLPatternInit] protocol: URLPatternComponentResult username: URLPatternComponentResult From e4f6c0554f34e4ac83cce3fa8f8975f46caf21c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=A9=EC=84=B1=EB=B2=94=20=28Bang=20Seongbeom=29?= Date: Tue, 27 Jan 2026 05:10:39 +0900 Subject: [PATCH 2/2] Add missing default value --- urlpattern.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/urlpattern.pyi b/urlpattern.pyi index fd14f52..73fb90e 100644 --- a/urlpattern.pyi +++ b/urlpattern.pyi @@ -42,7 +42,7 @@ class URLPattern: def __init__(self, input: str, options: None) -> None: ... @overload def __init__( - self, input: URLPatternInit, options: URLPatternOptions = {} + self, input: URLPatternInit = {}, options: URLPatternOptions = {} ) -> None: ... @overload def __init__(self, input: URLPatternInit, options: None) -> None: ...