Skip to content

Python3.8 additions and changes #3337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
24 changes: 16 additions & 8 deletions stdlib/2and3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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: ...
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
33 changes: 24 additions & 9 deletions stdlib/2and3/datetime.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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: ...
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion stdlib/2and3/fractions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion stdlib/2and3/shutil.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
21 changes: 21 additions & 0 deletions stdlib/3/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
6 changes: 6 additions & 0 deletions stdlib/3/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]: ...
Expand All @@ -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]: ...
Expand All @@ -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]):
Expand Down