|
43 | 43 | TypeVar, |
44 | 44 | Union, |
45 | 45 | cast, |
| 46 | + TYPE_CHECKING, |
| 47 | + overload, |
46 | 48 | ) |
47 | 49 | from unicodedata import normalize |
48 | 50 | from ._socket import inet_pton |
|
65 | 67 | QueryParameters = Union[ |
66 | 68 | Mapping[Text, Optional[Text]], |
67 | 69 | QueryPairs, |
68 | | - Sequence[Tuple[Text, Optional[Text]]], |
| 70 | + Iterable[Tuple[Text, Optional[Text]]], |
69 | 71 | ] |
70 | 72 | 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 |
71 | 76 |
|
72 | 77 |
|
73 | 78 | # from boltons.typeutils |
@@ -2415,6 +2420,25 @@ def __dir__(self): |
2415 | 2420 | # # End Twisted Compat Code |
2416 | 2421 |
|
2417 | 2422 |
|
| 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 | + |
2418 | 2442 | def parse(url, decoded=True, lazy=False): |
2419 | 2443 | # type: (Text, bool, bool) -> Union[URL, DecodedURL] |
2420 | 2444 | """ |
|
0 commit comments