Skip to content

Commit f3ca9f1

Browse files
Improve python typings for PyCharm
1 parent d3bc438 commit f3ca9f1

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

urlpattern.pyi

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
11
from typing_extensions import TypeAlias, TypedDict, overload
22

3-
URLPatternInput: TypeAlias = str | URLPatternInit
43

54
class URLPatternOptions(TypedDict, total=False):
65
ignoreCase: bool
76

7+
8+
class URLPatternInit(TypedDict, total=False):
9+
protocol: str
10+
username: str
11+
password: str
12+
hostname: str
13+
port: str
14+
pathname: str
15+
search: str
16+
hash: str
17+
baseURL: str
18+
819
class URLPattern:
920
@overload
1021
def __init__(
1122
self,
12-
input: URLPatternInput,
23+
input: URLPatternInit,
1324
baseURL: str,
1425
options: URLPatternOptions | None = None,
1526
): ...
1627
@overload
1728
def __init__(
18-
self, input: URLPatternInput, options: URLPatternOptions | None = None
29+
self,
30+
input: str,
31+
baseURL: str,
32+
options: URLPatternOptions | None = None,
1933
): ...
20-
def test(self, input: URLPatternInput = {}, baseURL: str | None = None) -> bool: ...
34+
@overload
35+
def __init__(
36+
self, input: URLPatternInit, options: URLPatternOptions | None = None
37+
): ...
38+
@overload
39+
def __init__(
40+
self, input: str, options: URLPatternOptions | None = None
41+
): ...
42+
@overload
43+
def test(self, input: URLPatternInit, baseURL: str | None = None) -> bool: ...
44+
@overload
45+
def test(self, input: str, baseURL: str | None = None) -> bool: ...
46+
@overload
2147
def exec(
22-
self, input: URLPatternInput = {}, baseURL: str | None = None
48+
self, input: URLPatternInit, baseURL: str | None = None
49+
) -> URLPatternResult | None: ...
50+
@overload
51+
def exec(
52+
self, input: str, baseURL: str | None = None
2353
) -> URLPatternResult | None: ...
2454
@property
2555
def protocol(self) -> str: ...
@@ -38,19 +68,9 @@ class URLPattern:
3868
@property
3969
def hash(self) -> str: ...
4070

41-
class URLPatternInit(TypedDict, total=False):
42-
protocol: str
43-
username: str
44-
password: str
45-
hostname: str
46-
port: str
47-
pathname: str
48-
search: str
49-
hash: str
50-
baseURL: str
5171

5272
class URLPatternResult(TypedDict):
53-
inputs: list[URLPatternInput]
73+
inputs: list[str | URLPatternInit]
5474

5575
protocol: URLPatternComponentResult
5676
username: URLPatternComponentResult

0 commit comments

Comments
 (0)