Avoid false positivies from urlparse (Python 2) (#4437)

PR #3887 changed some `str` types to `Union[str, unicode]`.  The `str`
types were too narrow, but the new types are too general, resulting in
around 80 false positives in a Dropbox internal repository.

I think that it's better to narrow down the types back some to avoid
the false positives, as these are commonly used functions.

Test cases:

```
from urlparse import urlunparse, urlunsplit, urljoin, urlparse, urlsplit

reveal_type(urlunparse(('1', '2', '3', '4', '5', '6'))) # str
reveal_type(urlunparse(['1', '2', '3', '4', '5', '6'])) # str
reveal_type(urlunparse((u'1', '2', '3', '4', '5', '6'))) # unicode
reveal_type(urlunparse([u'1', '2', '3', '4', '5', '6'])) # unicode

reveal_type(urlunsplit(('1', '2', '3', '4', '5'))) # str
reveal_type(urlunsplit(['1', '2', '3', '4', '5'])) # str
reveal_type(urlunsplit((u'1', '2', '3', '4', '5'))) # unicode
reveal_type(urlunsplit([u'1', '2', '3', '4', '5'])) # unicode

reveal_type(urljoin('x', 'y')) # str
reveal_type(urljoin(u'x', 'y')) # unicode
reveal_type(urljoin('x', u'y')) # unicode

reveal_type(urlparse('x').path) # str
reveal_type(urlparse(u'x').path) # str
reveal_type(urlparse(u'x').username) # Optional[str]

reveal_type(urlsplit('x').path) # str
reveal_type(urlsplit(u'x').path) # str
```
This commit is contained in:
Jukka Lehtosalo
2020-08-11 13:03:06 +01:00
committed by GitHub
parent 5c049cd136
commit 276d0428b9

View File

@@ -17,31 +17,31 @@ def clear_cache() -> None: ...
class ResultMixin(object):
@property
def username(self) -> Optional[_String]: ...
def username(self) -> Optional[str]: ...
@property
def password(self) -> Optional[_String]: ...
def password(self) -> Optional[str]: ...
@property
def hostname(self) -> Optional[_String]: ...
def hostname(self) -> Optional[str]: ...
@property
def port(self) -> Optional[int]: ...
class _SplitResult(NamedTuple):
scheme: _String
netloc: _String
path: _String
query: _String
fragment: _String
scheme: str
netloc: str
path: str
query: str
fragment: str
class SplitResult(_SplitResult, ResultMixin):
def geturl(self) -> _String: ...
def geturl(self) -> str: ...
class _ParseResult(NamedTuple):
scheme: _String
netloc: _String
path: _String
params: _String
query: _String
fragment: _String
scheme: str
netloc: str
path: str
params: str
query: str
fragment: str
class ParseResult(_ParseResult, ResultMixin):
def geturl(self) -> _String: ...
@@ -49,14 +49,14 @@ class ParseResult(_ParseResult, ResultMixin):
def urlparse(url: _String, scheme: _String = ..., allow_fragments: bool = ...) -> ParseResult: ...
def urlsplit(url: _String, scheme: _String = ..., allow_fragments: bool = ...) -> SplitResult: ...
@overload
def urlunparse(data: Tuple[_String, _String, _String, _String, _String, _String]) -> _String: ...
def urlunparse(data: Tuple[AnyStr, AnyStr, AnyStr, AnyStr, AnyStr, AnyStr]) -> AnyStr: ...
@overload
def urlunparse(data: Sequence[_String]) -> _String: ...
def urlunparse(data: Sequence[AnyStr]) -> AnyStr: ...
@overload
def urlunsplit(data: Tuple[_String, _String, _String, _String, _String]) -> _String: ...
def urlunsplit(data: Tuple[AnyStr, AnyStr, AnyStr, AnyStr, AnyStr]) -> AnyStr: ...
@overload
def urlunsplit(data: Sequence[_String]) -> _String: ...
def urljoin(base: _String, url: _String, allow_fragments: bool = ...) -> _String: ...
def urlunsplit(data: Sequence[AnyStr]) -> AnyStr: ...
def urljoin(base: AnyStr, url: AnyStr, allow_fragments: bool = ...) -> AnyStr: ...
def urldefrag(url: AnyStr) -> Tuple[AnyStr, AnyStr]: ...
def unquote(s: AnyStr) -> AnyStr: ...
def parse_qs(qs: AnyStr, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[AnyStr, List[AnyStr]]: ...