|
44 | 44 | Union, |
45 | 45 | cast, |
46 | 46 | TYPE_CHECKING, |
| 47 | + overload, |
47 | 48 | ) |
48 | 49 | from unicodedata import normalize |
49 | 50 | from ._socket import inet_pton |
@@ -2415,35 +2416,25 @@ def __dir__(self): |
2415 | 2416 |
|
2416 | 2417 | # # End Twisted Compat Code |
2417 | 2418 |
|
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. |
2419 | 2421 | 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 |
2435 | 2423 |
|
| 2424 | +@overload |
| 2425 | +def parse(url, decoded, lazy=False): |
| 2426 | + # type: (Text, Literal[False], bool) -> URL |
| 2427 | + """Passing decoded=False returns URL.""" |
2436 | 2428 |
|
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.""" |
2446 | 2433 |
|
| 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.""" |
2447 | 2438 |
|
2448 | 2439 | def parse(url, decoded=True, lazy=False): |
2449 | 2440 | # type: (Text, bool, bool) -> Union[URL, DecodedURL] |
|
0 commit comments