Allow math.trunc to only accept __trunc__-supporting objects (#6003)

Add SupportsTrunc protocol
This commit is contained in:
Bas van Beek
2021-09-04 18:16:53 +02:00
committed by GitHub
parent 3819f8e6ff
commit d599a535b2
2 changed files with 5 additions and 1 deletions

View File

@@ -41,6 +41,9 @@ class SupportsLenAndGetItem(Protocol[_T_co]):
def __len__(self) -> int: ...
def __getitem__(self, __k: int) -> _T_co: ...
class SupportsTrunc(Protocol):
def __trunc__(self) -> int: ...
# Mapping-like protocols
# stable

View File

@@ -1,4 +1,5 @@
import sys
from _typeshed import SupportsTrunc
from typing import Iterable, SupportsFloat, SupportsInt, Tuple, overload
e: float
@@ -94,7 +95,7 @@ def sinh(__x: SupportsFloat) -> float: ...
def sqrt(__x: SupportsFloat) -> float: ...
def tan(__x: SupportsFloat) -> float: ...
def tanh(__x: SupportsFloat) -> float: ...
def trunc(__x: SupportsFloat) -> int: ...
def trunc(__x: SupportsTrunc) -> int: ...
if sys.version_info >= (3, 9):
def ulp(__x: SupportsFloat) -> float: ...