mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-10 05:22:23 +08:00
Python3.8 additions and changes (#3337)
* Add as_integer_ratio() to a few types * Add dirs_exist_ok to copytree() * int, float, complex accept __index__ args Also fix complex.__init__ argument names * Add __reversed__ to dict et al. * Python 3.8 date(time) arithmetic fixes * Add CodeType.replace()
This commit is contained in:
committed by
Jelle Zijlstra
parent
d0beab9b8e
commit
8a7d61741d
@@ -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: ...
|
||||
def __init__(self, real: float = ..., imag: float = ...) -> None: ...
|
||||
@overload
|
||||
def __init__(self, s: str) -> 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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]],
|
||||
|
||||
Reference in New Issue
Block a user