Skip to content

Commit f8360b8

Browse files
authored
Merge pull request #157 from euresti/fix_some_type_issues
Fix some small type issues.
2 parents 2efaf03 + 0bb74e3 commit f8360b8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/hyperlink/_url.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
TypeVar,
4444
Union,
4545
cast,
46+
TYPE_CHECKING,
47+
overload,
4648
)
4749
from unicodedata import normalize
4850
from ._socket import inet_pton
@@ -65,9 +67,12 @@
6567
QueryParameters = Union[
6668
Mapping[Text, Optional[Text]],
6769
QueryPairs,
68-
Sequence[Tuple[Text, Optional[Text]]],
70+
Iterable[Tuple[Text, Optional[Text]]],
6971
]
7072
T = TypeVar("T")
73+
# Literal is not available in all pythons so we only bring it in for mypy.
74+
if TYPE_CHECKING:
75+
from typing import Literal
7176

7277

7378
# from boltons.typeutils
@@ -2415,6 +2420,25 @@ def __dir__(self):
24152420
# # End Twisted Compat Code
24162421

24172422

2423+
# Add some overloads so that parse gives a better return value.
2424+
@overload
2425+
def parse(url, decoded, lazy=False):
2426+
# type: (Text, Literal[False], bool) -> URL
2427+
"""Passing decoded=False returns URL."""
2428+
2429+
2430+
@overload
2431+
def parse(url, decoded=True, lazy=False):
2432+
# type: (Text, Literal[True], bool) -> DecodedURL
2433+
"""Passing decoded=True (or the default value) returns DecodedURL."""
2434+
2435+
2436+
@overload
2437+
def parse(url, decoded=True, lazy=False):
2438+
# type: (Text, bool, bool) -> Union[URL, DecodedURL]
2439+
"""If decoded is not a literal we don't know the return type."""
2440+
2441+
24182442
def parse(url, decoded=True, lazy=False):
24192443
# type: (Text, bool, bool) -> Union[URL, DecodedURL]
24202444
"""

0 commit comments

Comments
 (0)