diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 22299e34a707..ebbf032d6bbe 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -17,6 +17,11 @@ import sys if sys.version_info >= (3,): from typing import SupportsBytes, SupportsRound +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + _T = TypeVar('_T') _T_co = TypeVar('_T_co', covariant=True) _KT = TypeVar('_KT') @@ -29,6 +34,9 @@ _T4 = TypeVar('_T4') _T5 = TypeVar('_T5') _TT = TypeVar('_TT', bound='type') +class _SupportsIndex(Protocol): + def __index__(self) -> int: ... + class object: __doc__: Optional[str] __dict__: Dict[str, Any] @@ -129,10 +137,12 @@ class super(object): class int: @overload - def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, SupportsInt, _SupportsIndex] = ...) -> None: ... @overload def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ... + if sys.version_info >= (3, 8): + def as_integer_ratio(self) -> Tuple[int, Literal[1]]: ... @property def real(self) -> int: ... @property @@ -209,7 +219,7 @@ class int: def __index__(self) -> int: ... class float: - def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ... + def __init__(self, x: Union[SupportsFloat, _SupportsIndex, Text, bytes, bytearray] = ...) -> None: ... def as_integer_ratio(self) -> Tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @@ -271,11 +281,9 @@ class float: class complex: @overload - def __init__(self, re: float = ..., im: float = ...) -> None: ... - @overload - def __init__(self, s: str) -> None: ... + def __init__(self, real: float = ..., imag: float = ...) -> None: ... @overload - def __init__(self, s: SupportsComplex) -> None: ... + def __init__(self, real: Union[str, SupportsComplex, _SupportsIndex]) -> None: ... @property def real(self) -> float: ... @@ -987,6 +995,8 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __setitem__(self, k: _KT, v: _VT) -> None: ... def __delitem__(self, v: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... + if sys.version_info >= (3, 8): + def __reversed__(self) -> Iterator[_KT]: ... def __str__(self) -> str: ... __hash__: None # type: ignore @@ -1117,8 +1127,6 @@ if sys.version_info < (3,): if sys.version_info >= (3,): def ascii(__o: object) -> str: ... -class _SupportsIndex(Protocol): - def __index__(self) -> int: ... def bin(__number: Union[int, _SupportsIndex]) -> str: ... if sys.version_info >= (3, 7): diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 22299e34a707..ebbf032d6bbe 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -17,6 +17,11 @@ import sys if sys.version_info >= (3,): from typing import SupportsBytes, SupportsRound +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + _T = TypeVar('_T') _T_co = TypeVar('_T_co', covariant=True) _KT = TypeVar('_KT') @@ -29,6 +34,9 @@ _T4 = TypeVar('_T4') _T5 = TypeVar('_T5') _TT = TypeVar('_TT', bound='type') +class _SupportsIndex(Protocol): + def __index__(self) -> int: ... + class object: __doc__: Optional[str] __dict__: Dict[str, Any] @@ -129,10 +137,12 @@ class super(object): class int: @overload - def __init__(self, x: Union[Text, bytes, SupportsInt] = ...) -> None: ... + def __init__(self, x: Union[Text, bytes, SupportsInt, _SupportsIndex] = ...) -> None: ... @overload def __init__(self, x: Union[Text, bytes, bytearray], base: int) -> None: ... + if sys.version_info >= (3, 8): + def as_integer_ratio(self) -> Tuple[int, Literal[1]]: ... @property def real(self) -> int: ... @property @@ -209,7 +219,7 @@ class int: def __index__(self) -> int: ... class float: - def __init__(self, x: Union[SupportsFloat, Text, bytes, bytearray] = ...) -> None: ... + def __init__(self, x: Union[SupportsFloat, _SupportsIndex, Text, bytes, bytearray] = ...) -> None: ... def as_integer_ratio(self) -> Tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @@ -271,11 +281,9 @@ class float: class complex: @overload - def __init__(self, re: float = ..., im: float = ...) -> None: ... - @overload - def __init__(self, s: str) -> None: ... + def __init__(self, real: float = ..., imag: float = ...) -> None: ... @overload - def __init__(self, s: SupportsComplex) -> None: ... + def __init__(self, real: Union[str, SupportsComplex, _SupportsIndex]) -> None: ... @property def real(self) -> float: ... @@ -987,6 +995,8 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __setitem__(self, k: _KT, v: _VT) -> None: ... def __delitem__(self, v: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... + if sys.version_info >= (3, 8): + def __reversed__(self) -> Iterator[_KT]: ... def __str__(self) -> str: ... __hash__: None # type: ignore @@ -1117,8 +1127,6 @@ if sys.version_info < (3,): if sys.version_info >= (3,): def ascii(__o: object) -> str: ... -class _SupportsIndex(Protocol): - def __index__(self) -> int: ... def bin(__number: Union[int, _SupportsIndex]) -> str: ... if sys.version_info >= (3, 7): diff --git a/stdlib/2and3/datetime.pyi b/stdlib/2and3/datetime.pyi index df3fda4a3ae4..c462962e4673 100644 --- a/stdlib/2and3/datetime.pyi +++ b/stdlib/2and3/datetime.pyi @@ -1,9 +1,8 @@ import sys from time import struct_time -from typing import ( - AnyStr, Optional, SupportsAbs, Tuple, Union, overload, - ClassVar, -) +from typing import AnyStr, Optional, SupportsAbs, Tuple, Union, overload, ClassVar, Type, TypeVar + +_S = TypeVar("_S") if sys.version_info >= (3,): _Text = str @@ -68,7 +67,10 @@ class date: def __lt__(self, other: date) -> bool: ... def __ge__(self, other: date) -> bool: ... def __gt__(self, other: date) -> bool: ... - def __add__(self, other: timedelta) -> date: ... + if sys.version_info >= (3, 8): + def __add__(self: _S, other: timedelta) -> _S: ... + else: + def __add__(self, other: timedelta) -> date: ... @overload def __sub__(self, other: timedelta) -> date: ... @overload @@ -227,8 +229,16 @@ class datetime(date): def today(cls) -> datetime: ... @classmethod def fromordinal(cls, n: int) -> datetime: ... - @classmethod - def now(cls, tz: Optional[_tzinfo] = ...) -> datetime: ... + if sys.version_info >= (3, 8): + @classmethod + def now(cls: Type[_S], tz: Optional[_tzinfo] = ...) -> _S: ... + else: + @overload + @classmethod + def now(cls: Type[_S], tz: None = ...) -> _S: ... + @overload + @classmethod + def now(cls, tz: _tzinfo) -> datetime: ... @classmethod def utcnow(cls) -> datetime: ... if sys.version_info >= (3, 6): @@ -261,7 +271,9 @@ class datetime(date): def replace(self, year: int = ..., month: int = ..., day: int = ..., hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ..., tzinfo: Optional[_tzinfo] = ...) -> datetime: ... - if sys.version_info >= (3, 3): + if sys.version_info >= (3, 8): + def astimezone(self: _S, tz: Optional[_tzinfo] = ...) -> _S: ... + elif sys.version_info >= (3, 3): def astimezone(self, tz: Optional[_tzinfo] = ...) -> datetime: ... else: def astimezone(self, tz: _tzinfo) -> datetime: ... @@ -279,7 +291,10 @@ class datetime(date): def __lt__(self, other: datetime) -> bool: ... # type: ignore def __ge__(self, other: datetime) -> bool: ... # type: ignore def __gt__(self, other: datetime) -> bool: ... # type: ignore - def __add__(self, other: timedelta) -> datetime: ... + if sys.version_info >= (3, 8): + def __add__(self: _S, other: timedelta) -> _S: ... + else: + def __add__(self, other: timedelta) -> datetime: ... @overload # type: ignore def __sub__(self, other: datetime) -> timedelta: ... @overload diff --git a/stdlib/2and3/fractions.pyi b/stdlib/2and3/fractions.pyi index 8bebe5fc89e8..ce3f89f88419 100644 --- a/stdlib/2and3/fractions.pyi +++ b/stdlib/2and3/fractions.pyi @@ -4,7 +4,7 @@ # Note: these stubs are incomplete. The more complex type # signatures are currently omitted. Also see numbers.pyi. -from typing import Optional, TypeVar, Union, overload, Any +from typing import Optional, TypeVar, Union, overload, Any, Tuple from numbers import Real, Integral, Rational from decimal import Decimal import sys @@ -42,6 +42,8 @@ class Fraction(Rational): def from_decimal(cls, dec: Decimal) -> Fraction: ... def limit_denominator(self, max_denominator: int = ...) -> Fraction: ... + if sys.version_info >= (3, 8): + def as_integer_ratio(self) -> Tuple[int, int]: ... @property def numerator(self) -> int: ... @property diff --git a/stdlib/2and3/shutil.pyi b/stdlib/2and3/shutil.pyi index 98761d046f76..81ef46f565f2 100644 --- a/stdlib/2and3/shutil.pyi +++ b/stdlib/2and3/shutil.pyi @@ -72,7 +72,17 @@ else: def ignore_patterns(*patterns: _Path) -> Callable[[Any, List[_AnyStr]], Set[_AnyStr]]: ... -if sys.version_info >= (3,): +if sys.version_info >= (3, 8): + def copytree( + src: _Path, + dst: _Path, + symlinks: bool = ..., + ignore: Union[None, Callable[[str, List[str]], Iterable[str]], Callable[[_Path, List[str]], Iterable[str]]] = ..., + copy_function: Callable[[str, str], None] = ..., + ignore_dangling_symlinks: bool = ..., + dirs_exist_ok: bool = ..., + ) -> _PathReturn: ... +elif sys.version_info >= (3,): def copytree(src: _Path, dst: _Path, symlinks: bool = ..., ignore: Union[None, Callable[[str, List[str]], Iterable[str]], diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 61f87832ad9e..e1270afa5dc2 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -72,6 +72,27 @@ class CodeType: freevars: Tuple[str, ...] = ..., cellvars: Tuple[str, ...] = ..., ) -> None: ... + if sys.version_info >= (3, 8): + def replace( + self, + *, + co_argcount: int = ..., + co_posonlyargcount: int = ..., + co_kwonlyargcount: int = ..., + co_nlocals: int = ..., + co_stacksize: int = ..., + co_flags: int = ..., + co_firstlineno: int = ..., + co_code: bytes = ..., + co_consts: Tuple[Any, ...] = ..., + co_names: Tuple[str, ...] = ..., + co_varnames: Tuple[str, ...] = ..., + co_freevars: Tuple[str, ...] = ..., + co_cellvars: Tuple[str, ...] = ..., + co_filename: str = ..., + co_name: str = ..., + co_lnotab: bytes = ..., + ) -> CodeType: ... class MappingProxyType(Mapping[_KT, _VT], Generic[_KT, _VT]): def __init__(self, mapping: Mapping[_KT, _VT]) -> None: ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index fb279c01f46b..e6aa5465d735 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -339,6 +339,8 @@ class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co, def __rand__(self, o: Iterable[_T]) -> Set[_T]: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ... + if sys.version_info >= (3, 8): + def __reversed__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ... def __or__(self, o: Iterable[_T]) -> Set[Union[Tuple[_KT_co, _VT_co], _T]]: ... def __ror__(self, o: Iterable[_T]) -> Set[Union[Tuple[_KT_co, _VT_co], _T]]: ... def __sub__(self, o: Iterable[Any]) -> Set[Tuple[_KT_co, _VT_co]]: ... @@ -351,6 +353,8 @@ class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]): def __rand__(self, o: Iterable[_T]) -> Set[_T]: ... def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[_KT_co]: ... + if sys.version_info >= (3, 8): + def __reversed__(self) -> Iterator[_KT_co]: ... def __or__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... def __ror__(self, o: Iterable[_T]) -> Set[Union[_KT_co, _T]]: ... def __sub__(self, o: Iterable[Any]) -> Set[_KT_co]: ... @@ -361,6 +365,8 @@ class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]): class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]): def __contains__(self, o: object) -> bool: ... def __iter__(self) -> Iterator[_VT_co]: ... + if sys.version_info >= (3, 8): + def __reversed__(self) -> Iterator[_VT_co]: ... @runtime_checkable class ContextManager(Protocol[_T_co]):