Skip to content

Commit 5eb3896

Browse files
committed
Fix mypy
1 parent 240731f commit 5eb3896

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

src/hyperlink/_url.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
Union,
4545
cast,
4646
TYPE_CHECKING,
47+
overload,
4748
)
4849
from unicodedata import normalize
4950
from ._socket import inet_pton
@@ -2415,35 +2416,25 @@ def __dir__(self):
24152416

24162417
# # End Twisted Compat Code
24172418

2418-
2419+
# Add some overloads so that parse gives a better return value.
2420+
# Literal is not available in all pythons so we only bring it in for mypy.
24192421
if TYPE_CHECKING:
2420-
# Add some overloads so that parse gives a better return value.
2421-
# Literal is not available in all pythons so we only bring it in for mypy.
2422-
# Also to remain compatible with 2.7 we use pass instead of ...
2423-
from typing import Literal, overload
2424-
2425-
@overload
2426-
def parse(url):
2427-
# type: (Text) -> DecodedURL
2428-
pass
2429-
2430-
2431-
@overload
2432-
def parse(url, decoded, lazy=False):
2433-
# type: (Text, Literal[True], bool) -> DecodedURL
2434-
pass
2422+
from typing import Literal
24352423

2424+
@overload
2425+
def parse(url, decoded, lazy=False):
2426+
# type: (Text, Literal[False], bool) -> URL
2427+
"""Passing decoded=False returns URL."""
24362428

2437-
@overload
2438-
def parse(url, decoded, lazy=False):
2439-
# type: (Text, Literal[False], bool) -> URL
2440-
pass
2441-
2442-
@overload
2443-
def parse(url, decoded=True, lazy=False):
2444-
# type: (Text, bool, bool) -> Union[URL, DecodedURL]
2445-
pass
2429+
@overload
2430+
def parse(url, decoded=True, lazy=False):
2431+
# type: (Text, Literal[True], bool) -> DecodedURL
2432+
"""Passing decoded=True (or the default value) returns DecodedURL."""
24462433

2434+
@overload
2435+
def parse(url, decoded=True, lazy=False):
2436+
# type: (Text, bool, bool) -> Union[URL, DecodedURL]
2437+
"""If decoded is not a literal we don't know the return type."""
24472438

24482439
def parse(url, decoded=True, lazy=False):
24492440
# type: (Text, bool, bool) -> Union[URL, DecodedURL]

0 commit comments

Comments
 (0)