The filter function may return str, tuple or list (#2472)

In Python 2, the return type of filter depends on the iterable
parameter.
This commit is contained in:
Israel Tsadok
2018-09-26 06:26:23 +03:00
committed by Jelle Zijlstra
parent f73d060042
commit 2a30462c4a
2 changed files with 26 additions and 8 deletions

View File

@@ -739,11 +739,20 @@ def divmod(a: int, b: int) -> Tuple[int, int]: ...
def divmod(a: float, b: float) -> Tuple[float, float]: ...
def exit(code: Any = ...) -> NoReturn: ...
@overload
def filter(function: None,
iterable: Iterable[Optional[_T]]) -> List[_T]: ...
def filter(__function: Callable[[AnyStr], Any], # type: ignore
__iterable: AnyStr) -> AnyStr: ...
@overload
def filter(function: Callable[[_T], Any],
iterable: Iterable[_T]) -> List[_T]: ...
def filter(__function: None, # type: ignore
__iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ...
@overload
def filter(__function: Callable[[_T], Any], # type: ignore
__iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ...
@overload
def filter(__function: None,
__iterable: Iterable[Optional[_T]]) -> List[_T]: ...
@overload
def filter(__function: Callable[[_T], Any],
__iterable: Iterable[_T]) -> List[_T]: ...
def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode
def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ...
def hasattr(o: Any, name: unicode) -> bool: ...

View File

@@ -739,11 +739,20 @@ def divmod(a: int, b: int) -> Tuple[int, int]: ...
def divmod(a: float, b: float) -> Tuple[float, float]: ...
def exit(code: Any = ...) -> NoReturn: ...
@overload
def filter(function: None,
iterable: Iterable[Optional[_T]]) -> List[_T]: ...
def filter(__function: Callable[[AnyStr], Any], # type: ignore
__iterable: AnyStr) -> AnyStr: ...
@overload
def filter(function: Callable[[_T], Any],
iterable: Iterable[_T]) -> List[_T]: ...
def filter(__function: None, # type: ignore
__iterable: Tuple[Optional[_T], ...]) -> Tuple[_T, ...]: ...
@overload
def filter(__function: Callable[[_T], Any], # type: ignore
__iterable: Tuple[_T, ...]) -> Tuple[_T, ...]: ...
@overload
def filter(__function: None,
__iterable: Iterable[Optional[_T]]) -> List[_T]: ...
@overload
def filter(__function: Callable[[_T], Any],
__iterable: Iterable[_T]) -> List[_T]: ...
def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode
def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ...
def hasattr(o: Any, name: unicode) -> bool: ...