From 10939f833f0ef44f18198a9e9795df4b16b80508 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 15 Apr 2021 03:35:43 +0300 Subject: [PATCH 1/3] builtins stubtest exceptions --- stdlib/builtins.pyi | 185 +++++++++++++---------- tests/stubtest_whitelists/py3_common.txt | 29 +--- 2 files changed, 113 insertions(+), 101 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 78b29c5aa7e7..2a8e3dc12f41 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -472,14 +472,12 @@ class bytes(ByteString): def zfill(self, __width: int) -> bytes: ... @classmethod def fromhex(cls, __s: str) -> bytes: ... - @classmethod - def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + @staticmethod + def maketrans(__frm: bytes, __to: bytes) -> bytes: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... def __hash__(self) -> int: ... @overload def __getitem__(self, i: int) -> int: ... @@ -508,6 +506,7 @@ class bytearray(MutableSequence[int], ByteString): def __init__(self, string: str, encoding: str, errors: str = ...) -> None: ... @overload def __init__(self, length: int) -> None: ... + def append(self, __item: int) -> None: ... def capitalize(self) -> bytearray: ... def center(self, __width: int, __fillchar: bytes = ...) -> bytearray: ... def count(self, __sub: Union[bytes, int], __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... @@ -517,6 +516,7 @@ class bytearray(MutableSequence[int], ByteString): self, __suffix: Union[bytes, Tuple[bytes, ...]], __start: Optional[int] = ..., __end: Optional[int] = ... ) -> bool: ... def expandtabs(self, tabsize: int = ...) -> bytearray: ... + def extend(self, __iterable_of_ints: Iterable[int]) -> None: ... def find(self, __sub: Union[bytes, int], __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... if sys.version_info >= (3, 8): def hex(self, sep: Union[str, bytes] = ..., bytes_per_sep: int = ...) -> str: ... @@ -561,14 +561,12 @@ class bytearray(MutableSequence[int], ByteString): def zfill(self, __width: int) -> bytearray: ... @classmethod def fromhex(cls, __string: str) -> bytearray: ... - @classmethod - def maketrans(cls, __frm: bytes, __to: bytes) -> bytes: ... + @staticmethod + def maketrans(__frm: bytes, __to: bytes) -> bytes: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[int]: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... - def __int__(self) -> int: ... - def __float__(self) -> float: ... __hash__: None # type: ignore @overload def __getitem__(self, i: int) -> int: ... @@ -890,6 +888,9 @@ class range(Sequence[int]): def __reversed__(self) -> Iterator[int]: ... class property(object): + fget: Optional[Callable[[Any], Any]] + fset: Optional[Callable[[Any, Any], None]] + fdel: Optional[Callable[[Any], None]] def __init__( self, fget: Optional[Callable[[Any], Any]] = ..., @@ -903,9 +904,6 @@ class property(object): def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ... def __set__(self, obj: Any, value: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... - def fget(self) -> Any: ... - def fset(self, value: Any) -> None: ... - def fdel(self) -> None: ... class _NotImplementedType(Any): # type: ignore # A little weird, but typing the __call__ as NotImplemented makes the error message @@ -973,10 +971,15 @@ def exec( __locals: Optional[Mapping[str, Any]] = ..., ) -> Any: ... def exit(code: object = ...) -> NoReturn: ... -@overload -def filter(__function: None, __iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... -@overload -def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Iterator[_T]: ... + +class filter(Iterator[_T], Generic[_T]): + @overload + def __init__(self, __function: None, __iterable: Iterable[Optional[_T]]) -> None: ... + @overload + def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ... + def __iter__(self) -> Iterator[_T]: ... + def __next__(self) -> _T: ... + def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode def getattr(__o: Any, name: str, __default: Any = ...) -> Any: ... def globals() -> Dict[str, Any]: ... @@ -997,42 +1000,50 @@ def issubclass(__cls: type, __class_or_tuple: Union[type, Tuple[Union[type, Tupl def len(__obj: Sized) -> int: ... def license() -> None: ... def locals() -> Dict[str, Any]: ... -@overload -def map(__func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> Iterator[_S]: ... -@overload -def map(__func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Iterator[_S]: ... -@overload -def map( - __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3] -) -> Iterator[_S]: ... -@overload -def map( - __func: Callable[[_T1, _T2, _T3, _T4], _S], - __iter1: Iterable[_T1], - __iter2: Iterable[_T2], - __iter3: Iterable[_T3], - __iter4: Iterable[_T4], -) -> Iterator[_S]: ... -@overload -def map( - __func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], - __iter1: Iterable[_T1], - __iter2: Iterable[_T2], - __iter3: Iterable[_T3], - __iter4: Iterable[_T4], - __iter5: Iterable[_T5], -) -> Iterator[_S]: ... -@overload -def map( - __func: Callable[..., _S], - __iter1: Iterable[Any], - __iter2: Iterable[Any], - __iter3: Iterable[Any], - __iter4: Iterable[Any], - __iter5: Iterable[Any], - __iter6: Iterable[Any], - *iterables: Iterable[Any], -) -> Iterator[_S]: ... + +class map(Iterator[_S], Generic[_S]): + @overload + def __init__(self, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> None: ... + @overload + def __init__(self, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> None: ... + @overload + def __init__( + self, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3] + ) -> None: ... + @overload + def __init__( + self, + __func: Callable[[_T1, _T2, _T3, _T4], _S], + __iter1: Iterable[_T1], + __iter2: Iterable[_T2], + __iter3: Iterable[_T3], + __iter4: Iterable[_T4], + ) -> None: ... + @overload + def __init__( + self, + __func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + __iter1: Iterable[_T1], + __iter2: Iterable[_T2], + __iter3: Iterable[_T3], + __iter4: Iterable[_T4], + __iter5: Iterable[_T5], + ) -> None: ... + @overload + def __init__( + self, + __func: Callable[..., _S], + __iter1: Iterable[Any], + __iter2: Iterable[Any], + __iter3: Iterable[Any], + __iter4: Iterable[Any], + __iter5: Iterable[Any], + __iter6: Iterable[Any], + *iterables: Iterable[Any], + ) -> None: ... + def __iter__(self) -> Iterator[_S]: ... + def __next__(self) -> _S: ... + @overload def max( __arg1: SupportsLessThanT, __arg2: SupportsLessThanT, *_args: SupportsLessThanT, key: None = ... @@ -1201,10 +1212,15 @@ else: def pow(__base: _SupportsPow3[_E, _M, _T_co], __exp: _E, __mod: _M) -> _T_co: ... def quit(code: object = ...) -> NoReturn: ... -@overload -def reversed(__sequence: Sequence[_T]) -> Iterator[_T]: ... -@overload -def reversed(__sequence: Reversible[_T]) -> Iterator[_T]: ... + +class reversed(Iterator[_T], Generic[_T]): + @overload + def __init__(self, __sequence: Sequence[_T]) -> None: ... + @overload + def __init__(self, __sequence: Reversible[_T]) -> None: ... + def __iter__(self) -> Iterator[_T]: ... + def __next__(self) -> _T: ... + def repr(__obj: object) -> str: ... @overload def round(number: SupportsRound[Any]) -> int: ... @@ -1231,30 +1247,41 @@ else: def sum(__iterable: Iterable[_T], __start: _S) -> Union[_T, _S]: ... def vars(__object: Any = ...) -> Dict[str, Any]: ... -@overload -def zip(__iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... -@overload -def zip(__iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... -@overload -def zip(__iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... -@overload -def zip( - __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], __iter4: Iterable[_T4] -) -> Iterator[Tuple[_T1, _T2, _T3, _T4]]: ... -@overload -def zip( - __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], __iter4: Iterable[_T4], __iter5: Iterable[_T5] -) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... -@overload -def zip( - __iter1: Iterable[Any], - __iter2: Iterable[Any], - __iter3: Iterable[Any], - __iter4: Iterable[Any], - __iter5: Iterable[Any], - __iter6: Iterable[Any], - *iterables: Iterable[Any], -) -> Iterator[Tuple[Any, ...]]: ... + +class zip(Iterator[_T_co], Generic[_T_co]): + @overload + def __new__(cls, __iter1: Iterable[_T1]) -> zip[Tuple[_T1]]: ... + @overload + def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> zip[Tuple[_T1, _T2]]: ... + @overload + def __new__(cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]: ... + @overload + def __new__( + cls, __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3], __iter4: Iterable[_T4] + ) -> zip[Tuple[_T1, _T2, _T3, _T4]]: ... + @overload + def __new__( + cls, + __iter1: Iterable[_T1], + __iter2: Iterable[_T2], + __iter3: Iterable[_T3], + __iter4: Iterable[_T4], + __iter5: Iterable[_T5], + ) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... + @overload + def __new__( + cls, + __iter1: Iterable[Any], + __iter2: Iterable[Any], + __iter3: Iterable[Any], + __iter4: Iterable[Any], + __iter5: Iterable[Any], + __iter6: Iterable[Any], + *iterables: Iterable[Any], + ) -> zip[Tuple[Any, ...]]: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __next__(self) -> _T_co: ... + def __import__( name: str, globals: Optional[Mapping[str, Any]] = ..., diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 47530a47a456..4c3179ec8eb6 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -49,30 +49,15 @@ asyncio.locks.Condition.locked asyncio.locks.Condition.release asyncio.proactor_events.BaseProactorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation asyncio.selector_events.BaseSelectorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation -builtins.bytearray.__float__ -builtins.bytearray.__int__ -builtins.bytearray.append -builtins.bytearray.extend -builtins.bytearray.maketrans -builtins.bytes.__float__ -builtins.bytes.__int__ -builtins.bytes.maketrans -builtins.classmethod.__get__ -builtins.ellipsis -builtins.filter # not a function at runtime +builtins.classmethod.__get__ # this function can accpet no value for the type parameter. +builtins.ellipsis # type is not exposed anywhere builtins.function -builtins.map # not a function at runtime -builtins.memoryview.__contains__ -builtins.memoryview.__iter__ +builtins.memoryview.__contains__ # C type that implements __getitem__ +builtins.memoryview.__iter__ # C type that implements __getitem__ builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only -builtins.object.__init__ -builtins.property.__get__ -builtins.property.fdel -builtins.property.fget -builtins.property.fset -builtins.reversed # not a function at runtime -builtins.staticmethod.__get__ -builtins.zip # not a function at runtime +builtins.object.__init__ # default C signature is incorrect +builtins.property.__get__ # this function can accpet no value for the type parameter. +builtins.staticmethod.__get__ # this function can accpet no value for the type parameter. bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set # The following methods were changed in point releases from Python 3.6 to 3.9 # as part of a security fix. These excludes can be removed when the GitHub From 9b2d018f898149c26f6e8ca4c26a96327a37c948 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Thu, 15 Apr 2021 07:42:58 +0300 Subject: [PATCH 2/3] Update tests/stubtest_whitelists/py3_common.txt Co-authored-by: Jelle Zijlstra --- tests/stubtest_whitelists/py3_common.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 4c3179ec8eb6..7e145fb69207 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -49,7 +49,7 @@ asyncio.locks.Condition.locked asyncio.locks.Condition.release asyncio.proactor_events.BaseProactorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation asyncio.selector_events.BaseSelectorEventLoop.sock_recv # nbytes parameter has different name 'n' in implementation -builtins.classmethod.__get__ # this function can accpet no value for the type parameter. +builtins.classmethod.__get__ # this function can accept no value for the type parameter. builtins.ellipsis # type is not exposed anywhere builtins.function builtins.memoryview.__contains__ # C type that implements __getitem__ From 9d4536f7a723c19667fe8cd9df7d606a948ea196 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Thu, 15 Apr 2021 07:43:04 +0300 Subject: [PATCH 3/3] Update tests/stubtest_whitelists/py3_common.txt Co-authored-by: Jelle Zijlstra --- tests/stubtest_whitelists/py3_common.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 7e145fb69207..6772afde2c46 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -56,8 +56,8 @@ builtins.memoryview.__contains__ # C type that implements __getitem__ builtins.memoryview.__iter__ # C type that implements __getitem__ builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only builtins.object.__init__ # default C signature is incorrect -builtins.property.__get__ # this function can accpet no value for the type parameter. -builtins.staticmethod.__get__ # this function can accpet no value for the type parameter. +builtins.property.__get__ # this function can accept no value for the type parameter. +builtins.staticmethod.__get__ # this function can accept no value for the type parameter. bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set # The following methods were changed in point releases from Python 3.6 to 3.9 # as part of a security fix. These excludes can be removed when the GitHub