Unify stdlib/{2,3}/typing.pyi

Also fix signature of IO.seek, IO.truncate, IO.write, and MutableMapping.update
Fixes #1016

Note: I couldn't put typing.pyi in 2and3 because of an import cycle when adding `import sys` to 2/typing.pyi
This commit is contained in:
David Euresti
2017-03-17 16:02:06 -07:00
committed by Łukasz Langa
parent 37a854630c
commit d43f3be914
8 changed files with 55 additions and 36 deletions

View File

@@ -13,11 +13,12 @@ Tuple = object()
Callable = object()
Type = object()
_promote = object()
no_type_check = object()
ClassVar = object()
class GenericMeta(type): ...
# Type aliases
# Type aliases and type constructors
class TypeAlias:
# Class for defining generic aliases for library types.
@@ -57,6 +58,10 @@ class SupportsFloat(metaclass=ABCMeta):
@abstractmethod
def __float__(self) -> float: ...
class SupportsComplex(metaclass=ABCMeta):
@abstractmethod
def __complex__(self) -> complex: ...
class SupportsAbs(Generic[_T]):
@abstractmethod
def __abs__(self) -> _T: ...
@@ -73,6 +78,13 @@ class Sized(metaclass=ABCMeta):
@abstractmethod
def __len__(self) -> int: ...
class Hashable(metaclass=ABCMeta):
# TODO: This is special, in that a subclass of a hashable class may not be hashable
# (for example, list vs. object). It's not obvious how to represent this. This class
# is currently mostly useless for static checking.
@abstractmethod
def __hash__(self) -> int: ...
class Iterable(Generic[_T_co]):
@abstractmethod
def __iter__(self) -> Iterator[_T_co]: ...
@@ -89,7 +101,9 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]):
def send(self, value: _T_contra) -> _T_co: ...
@abstractmethod
def throw(self, typ: BaseException, val: Any = None, tb: Any = None) -> None: ...
def throw(self, typ: Type[BaseException], val: Optional[BaseException] = None,
# TODO: tb should be TracebackType but that's defined in types
tb: Any = None) -> None: ...
@abstractmethod
def close(self) -> None: ...
@@ -121,8 +135,12 @@ class MutableSequence(Sequence[_T], Generic[_T]):
@overload
@abstractmethod
def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...
@overload
@abstractmethod
def __delitem__(self, i: Union[int, slice]) -> None: ...
def __delitem__(self, i: int) -> None: ...
@overload
@abstractmethod
def __delitem__(self, i: slice) -> None: ...
# Mixin methods
def append(self, object: _T) -> None: ...
def extend(self, iterable: Iterable[_T]) -> None: ...
@@ -242,18 +260,18 @@ class IO(Iterator[AnyStr], Generic[AnyStr]):
@abstractmethod
def readlines(self, hint: int = ...) -> list[AnyStr]: ...
@abstractmethod
def seek(self, offset: int, whence: int = ...) -> None: ...
def seek(self, offset: int, whence: int = ...) -> int: ...
@abstractmethod
def seekable(self) -> bool: ...
@abstractmethod
def tell(self) -> int: ...
@abstractmethod
def truncate(self, size: int = ...) -> Optional[int]: ...
def truncate(self, size: Optional[int] = ...) -> int: ...
@abstractmethod
def writable(self) -> bool: ...
# TODO buffer objects
@abstractmethod
def write(self, s: AnyStr) -> None: ...
def write(self, s: AnyStr) -> int: ...
@abstractmethod
def writelines(self, lines: Iterable[AnyStr]) -> None: ...
@@ -290,6 +308,8 @@ class TextIO(IO[unicode]):
@abstractmethod
def __enter__(self) -> TextIO: ...
class ByteString(Sequence[int]): ...
class Match(Generic[AnyStr]):
pos = 0
endpos = 0