Skip to content

Commit

Permalink
Sync typeshed (#10862)
Browse files Browse the repository at this point in the history
Source commit:
python/typeshed@581b2d5

* add some fixtures

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored Aug 4, 2021
1 parent 18ff207 commit d131e91
Show file tree
Hide file tree
Showing 101 changed files with 2,416 additions and 1,246 deletions.
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/@python2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,14 @@ def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> List[_T
def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode
@overload
def getattr(__o: Any, name: Text) -> Any: ...

# While technically covered by the last overload, spelling out the types for None and bool
# help mypy out in some tricky situations involving type context (aka bidirectional inference)
@overload
def getattr(__o: Any, name: Text, __default: None) -> Optional[Any]: ...
@overload
def getattr(__o: Any, name: Text, __default: bool) -> Union[Any, bool]: ...
@overload
def getattr(__o: Any, name: Text, __default: _T) -> Union[Any, _T]: ...
def globals() -> Dict[str, Any]: ...
def hasattr(__obj: Any, __name: Text) -> bool: ...
Expand Down
7 changes: 4 additions & 3 deletions mypy/typeshed/stdlib/@python2/_io.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Self
from mmap import mmap
from typing import IO, Any, BinaryIO, Iterable, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union

Expand Down Expand Up @@ -30,7 +31,7 @@ class _IOBase(BinaryIO):
def tell(self) -> int: ...
def truncate(self, size: Optional[int] = ...) -> int: ...
def writable(self) -> bool: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]
) -> Optional[bool]: ...
Expand All @@ -56,7 +57,7 @@ class _BufferedIOBase(_IOBase):
class BufferedRWPair(_BufferedIOBase):
def __init__(self, reader: _RawIOBase, writer: _RawIOBase, buffer_size: int = ..., max_buffer_size: int = ...) -> None: ...
def peek(self, n: int = ...) -> bytes: ...
def __enter__(self) -> BufferedRWPair: ...
def __enter__(self: Self) -> Self: ...

class BufferedRandom(_BufferedIOBase):
mode: str
Expand Down Expand Up @@ -140,7 +141,7 @@ class _TextIOBase(TextIO):
def writable(self) -> bool: ...
def write(self, pbuf: unicode) -> int: ...
def writelines(self, lines: Iterable[unicode]) -> None: ...
def __enter__(self: _T) -> _T: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]
) -> Optional[bool]: ...
Expand Down
4 changes: 4 additions & 0 deletions mypy/typeshed/stdlib/@python2/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ _T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_contra = TypeVar("_T_contra", contravariant=True)

# Use for "self" annotations:
# def __enter__(self: Self) -> Self: ...
Self = TypeVar("Self") # noqa Y001

class IdentityFunction(Protocol):
def __call__(self, __x: _T) -> _T: ...

Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/@python2/abc.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _weakrefset
from _typeshed import SupportsWrite
from typing import Any, Callable, Dict, Set, Tuple, Type, TypeVar

_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
Expand All @@ -8,17 +9,16 @@ _FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
def abstractmethod(funcobj: _FuncT) -> _FuncT: ...

class ABCMeta(type):
# TODO: FrozenSet
__abstractmethods__: Set[Any]
__abstractmethods__: frozenset[str]
_abc_cache: _weakrefset.WeakSet[Any]
_abc_invalidation_counter: int
_abc_negative_cache: _weakrefset.WeakSet[Any]
_abc_negative_cache_version: int
_abc_registry: _weakrefset.WeakSet[Any]
def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[Any, Any]) -> None: ...
def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> None: ...
def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ...
def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ...
def _dump_registry(cls: ABCMeta, *args: Any, **kwargs: Any) -> None: ...
def _dump_registry(cls: ABCMeta, file: SupportsWrite[Any] | None = ...) -> None: ...
def register(cls: ABCMeta, subclass: Type[Any]) -> None: ...

# TODO: The real abc.abstractproperty inherits from "property".
Expand Down
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/@python2/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,14 @@ def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> List[_T
def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode
@overload
def getattr(__o: Any, name: Text) -> Any: ...

# While technically covered by the last overload, spelling out the types for None and bool
# help mypy out in some tricky situations involving type context (aka bidirectional inference)
@overload
def getattr(__o: Any, name: Text, __default: None) -> Optional[Any]: ...
@overload
def getattr(__o: Any, name: Text, __default: bool) -> Union[Any, bool]: ...
@overload
def getattr(__o: Any, name: Text, __default: _T) -> Union[Any, _T]: ...
def globals() -> Dict[str, Any]: ...
def hasattr(__obj: Any, __name: Text) -> bool: ...
Expand Down
14 changes: 6 additions & 8 deletions mypy/typeshed/stdlib/@python2/mmap.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import AnyStr, Generic, Optional, Sequence, Union
from typing import NoReturn, Optional, Sequence, Union

ACCESS_DEFAULT: int
ACCESS_READ: int
Expand All @@ -23,7 +23,7 @@ if sys.platform != "win32":

PAGESIZE: int

class _mmap(Generic[AnyStr]):
class mmap(Sequence[bytes]):
if sys.platform == "win32":
def __init__(
self, fileno: int, length: int, tagname: Optional[str] = ..., access: int = ..., offset: int = ...
Expand All @@ -35,21 +35,19 @@ class _mmap(Generic[AnyStr]):
def close(self) -> None: ...
def flush(self, offset: int = ..., size: int = ...) -> int: ...
def move(self, dest: int, src: int, count: int) -> None: ...
def read_byte(self) -> AnyStr: ...
def readline(self) -> AnyStr: ...
def read_byte(self) -> bytes: ...
def readline(self) -> bytes: ...
def resize(self, newsize: int) -> None: ...
def seek(self, pos: int, whence: int = ...) -> None: ...
def size(self) -> int: ...
def tell(self) -> int: ...
def write_byte(self, byte: AnyStr) -> None: ...
def write_byte(self, byte: bytes) -> None: ...
def __len__(self) -> int: ...

class mmap(_mmap[bytes], Sequence[bytes]):
def find(self, string: bytes, start: int = ..., end: int = ...) -> int: ...
def rfind(self, string: bytes, start: int = ..., stop: int = ...) -> int: ...
def read(self, num: int) -> bytes: ...
def write(self, string: bytes) -> None: ...
def __getitem__(self, index: Union[int, slice]) -> bytes: ...
def __getslice__(self, i: Optional[int], j: Optional[int]) -> bytes: ...
def __delitem__(self, index: Union[int, slice]) -> None: ...
def __delitem__(self, index: Union[int, slice]) -> NoReturn: ...
def __setitem__(self, index: Union[int, slice], object: bytes) -> None: ...
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/@python2/sysconfig.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_config_vars() -> Dict[str, Any]: ...
def get_config_vars(arg: str, *args: str) -> List[Any]: ...
def get_scheme_names() -> Tuple[str, ...]: ...
def get_path_names() -> Tuple[str, ...]: ...
def get_path(name: str, scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> Optional[str]: ...
def get_path(name: str, scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> str: ...
def get_paths(scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> Dict[str, str]: ...
def get_python_version() -> str: ...
def get_platform() -> str: ...
Expand Down
5 changes: 4 additions & 1 deletion mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _ast: 2.7-
_bisect: 2.7-
_bootlocale: 3.6-3.9
_codecs: 2.7-
_collections_abc: 3.6-
_collections_abc: 3.3-
_compat_pickle: 3.6-
_compression: 3.6-
_csv: 2.7-
Expand All @@ -43,6 +43,7 @@ _py_abc: 3.7-
_pydecimal: 3.6-
_random: 2.7-
_sitebuiltins: 3.6-
_socket: 3.0- # present in 2.7 at runtime, but not in typeshed
_stat: 3.6-
_thread: 2.7-
_threading_local: 3.6-
Expand Down Expand Up @@ -82,6 +83,7 @@ code: 2.7-
codecs: 2.7-
codeop: 2.7-
collections: 2.7-
collections.abc: 3.3-
colorsys: 2.7-
compileall: 2.7-
concurrent: 3.2-
Expand Down Expand Up @@ -135,6 +137,7 @@ imaplib: 2.7-
imghdr: 2.7-
imp: 2.7-
importlib: 2.7-
importlib.metadata: 3.8-
importlib.resources: 3.7-
inspect: 2.7-
io: 2.7-
Expand Down
28 changes: 28 additions & 0 deletions mypy/typeshed/stdlib/__future__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ if sys.version_info >= (3, 7):
annotations: _Feature

all_feature_names: List[str] # undocumented

if sys.version_info >= (3, 7):
__all__ = [
"all_feature_names",
"absolute_import",
"division",
"generators",
"nested_scopes",
"print_function",
"unicode_literals",
"with_statement",
"barry_as_FLUFL",
"generator_stop",
"annotations",
]
else:
__all__ = [
"all_feature_names",
"absolute_import",
"division",
"generators",
"nested_scopes",
"print_function",
"unicode_literals",
"with_statement",
"barry_as_FLUFL",
"generator_stop",
]
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/_ast.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import typing
from typing import Any, ClassVar, Optional
from typing_extensions import Literal

PyCF_ONLY_AST: int
if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -390,7 +391,7 @@ if sys.version_info >= (3, 10):
class MatchValue(pattern):
value: expr
class MatchSingleton(pattern):
value: Optional[bool]
value: Literal[True, False, None]
class MatchSequence(pattern):
patterns: typing.List[pattern]
class MatchStar(pattern):
Expand Down
11 changes: 11 additions & 0 deletions mypy/typeshed/stdlib/_curses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ BUTTON4_DOUBLE_CLICKED: int
BUTTON4_PRESSED: int
BUTTON4_RELEASED: int
BUTTON4_TRIPLE_CLICKED: int
# Darwin ncurses doesn't provide BUTTON5_* constants
if sys.version_info >= (3, 10) and sys.platform != "darwin":
BUTTON5_PRESSED: int
BUTTON5_RELEASED: int
BUTTON5_CLICKED: int
BUTTON5_DOUBLE_CLICKED: int
BUTTON5_TRIPLE_CLICKED: int
BUTTON_ALT: int
BUTTON_CTRL: int
BUTTON_SHIFT: int
Expand Down Expand Up @@ -291,6 +298,10 @@ def getsyx() -> Tuple[int, int]: ...
def getwin(__file: BinaryIO) -> _CursesWindow: ...
def halfdelay(__tenths: int) -> None: ...
def has_colors() -> bool: ...

if sys.version_info >= (3, 10):
def has_extended_color_support() -> bool: ...

def has_ic() -> bool: ...
def has_il() -> bool: ...
def has_key(__key: int) -> bool: ...
Expand Down
Loading

0 comments on commit d131e91

Please sign in to comment.