From ae9d4f4b21bb5e1239816c301da7b1ea904b44c3 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 19 May 2019 00:14:39 +0200 Subject: [PATCH] Make builtins work - Jedi cannot really deal with __new__. - A typeshed issue: "function" should not be defined in the stubs. - Jedi cannot deal with the weird __call__: NotImplemented typing, because it's recursive. --- stdlib/3/builtins.pyi | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 58ab271d1..fdaab4297 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -166,6 +166,10 @@ class int: def __new__(cls: Type[_T], x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc] = ...) -> _T: ... @overload def __new__(cls: Type[_T], x: Union[str, bytes, bytearray], base: int) -> _T: ... + @overload + def __init__(self, x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc] = ...) -> _T: ... + @overload + def __init__(self, x: Union[str, bytes, bytearray], base: int) -> _T: ... if sys.version_info >= (3, 8): def as_integer_ratio(self) -> Tuple[int, Literal[1]]: ... @property @@ -326,6 +330,10 @@ class str(Sequence[str]): def __new__(cls: Type[_T], o: object = ...) -> _T: ... @overload def __new__(cls: Type[_T], o: bytes, encoding: str = ..., errors: str = ...) -> _T: ... + @overload + def __init__(self, o: object = ...) -> _T: ... + @overload + def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> _T: ... def capitalize(self) -> str: ... def casefold(self) -> str: ... def center(self, __width: int, __fillchar: str = ...) -> str: ... @@ -622,6 +630,7 @@ class memoryview(Sized, Container[int]): class bool(int): def __new__(cls: Type[_T], __o: object = ...) -> _T: ... + def __init__(self, o: object = ...): ... @overload def __and__(self, x: bool) -> bool: ... @overload @@ -661,6 +670,7 @@ class slice(object): class tuple(Sequence[_T_co], Generic[_T_co]): def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ... + def __init__(self, iterable: Iterable[_T_co] = ...): ... def __len__(self) -> int: ... def __contains__(self, x: object) -> bool: ... @overload @@ -683,14 +693,6 @@ class tuple(Sequence[_T_co], Generic[_T_co]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... -class function: - # TODO not defined in builtins! - __name__: str - __module__: str - __code__: CodeType - __qualname__: str - __annotations__: Dict[str, Any] - class list(MutableSequence[_T], Generic[_T]): @overload def __init__(self) -> None: ... @@ -743,7 +745,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): @overload def __init__(self, **kwargs: _VT) -> None: ... @overload - def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None: ... + def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... @overload def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... @@ -892,7 +894,7 @@ class property(object): class _NotImplementedType(Any): # type: ignore # A little weird, but typing the __call__ as NotImplemented makes the error message # for NotImplemented() much better - __call__: NotImplemented # type: ignore + pass NotImplemented: _NotImplementedType