Skip to content

Commit

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

This reapplies #13093. This will likely be the last sync that still has support for Python 3.6.
  • Loading branch information
hauntsaninja authored Jul 8, 2022
1 parent 256f1f3 commit 3ae19a2
Show file tree
Hide file tree
Showing 76 changed files with 2,777 additions and 1,239 deletions.
7 changes: 4 additions & 3 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
else:
import tomli as tomllib

from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence,
TextIO, Tuple, Union)
from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence,
TextIO, Tuple, Union, Iterable)
from typing_extensions import Final, TypeAlias as _TypeAlias

from mypy import defaults
Expand Down Expand Up @@ -179,7 +179,8 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None],
if filename is not None:
config_files: Tuple[str, ...] = (filename,)
else:
config_files = tuple(map(os.path.expanduser, defaults.CONFIG_FILES))
config_files_iter: Iterable[str] = map(os.path.expanduser, defaults.CONFIG_FILES)
config_files = tuple(config_files_iter)

config_parser = configparser.RawConfigParser()

Expand Down
5 changes: 4 additions & 1 deletion mypy/typeshed/stdlib/@python2/itertools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class chain(Iterator[_T], Generic[_T]):

def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ...
def dropwhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
def ifilter(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ...
@overload
def ifilter(predicate: None, iterable: Iterable[_T | None]) -> Iterator[_T]: ...
@overload
def ifilter(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
def ifilterfalse(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ...
@overload
def groupby(iterable: Iterable[_T], key: None = ...) -> Iterator[tuple[_T, Iterator[_T]]]: ...
Expand Down
9 changes: 6 additions & 3 deletions mypy/typeshed/stdlib/__future__.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sys
from typing_extensions import TypeAlias

_VersionInfo: TypeAlias = tuple[int, int, int, str, int]

class _Feature:
def __init__(self, optionalRelease: sys._version_info, mandatoryRelease: sys._version_info, compiler_flag: int) -> None: ...
def getOptionalRelease(self) -> sys._version_info: ...
def getMandatoryRelease(self) -> sys._version_info: ...
def __init__(self, optionalRelease: _VersionInfo, mandatoryRelease: _VersionInfo | None, compiler_flag: int) -> None: ...
def getOptionalRelease(self) -> _VersionInfo: ...
def getMandatoryRelease(self) -> _VersionInfo | None: ...
compiler_flag: int

absolute_import: _Feature
Expand Down
50 changes: 25 additions & 25 deletions mypy/typeshed/stdlib/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if sys.version_info >= (3, 8):
PyCF_TYPE_COMMENTS: Literal[4096]
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]

_identifier: TypeAlias = str
_Identifier: TypeAlias = str

class AST:
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -61,7 +61,7 @@ class stmt(AST): ...
class FunctionDef(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
name: _identifier
name: _Identifier
args: arguments
body: list[stmt]
decorator_list: list[expr]
Expand All @@ -70,7 +70,7 @@ class FunctionDef(stmt):
class AsyncFunctionDef(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
name: _identifier
name: _Identifier
args: arguments
body: list[stmt]
decorator_list: list[expr]
Expand All @@ -79,7 +79,7 @@ class AsyncFunctionDef(stmt):
class ClassDef(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list")
name: _identifier
name: _Identifier
bases: list[expr]
keywords: list[keyword]
body: list[stmt]
Expand Down Expand Up @@ -194,19 +194,19 @@ class Import(stmt):
class ImportFrom(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("module", "names", "level")
module: _identifier | None
module: _Identifier | None
names: list[alias]
level: int

class Global(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("names",)
names: list[_identifier]
names: list[_Identifier]

class Nonlocal(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("names",)
names: list[_identifier]
names: list[_Identifier]

class Expr(stmt):
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -362,16 +362,16 @@ class Attribute(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("value", "attr", "ctx")
value: expr
attr: _identifier
attr: _Identifier
ctx: expr_context

if sys.version_info >= (3, 9):
_SliceT: TypeAlias = expr
_Slice: TypeAlias = expr
else:
class slice(AST): ...
_SliceT: TypeAlias = slice
_Slice: TypeAlias = slice

class Slice(_SliceT):
class Slice(_Slice):
if sys.version_info >= (3, 10):
__match_args__ = ("lower", "upper", "step")
lower: expr | None
Expand All @@ -389,7 +389,7 @@ class Subscript(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("value", "slice", "ctx")
value: expr
slice: _SliceT
slice: _Slice
ctx: expr_context

class Starred(expr):
Expand All @@ -401,7 +401,7 @@ class Starred(expr):
class Name(expr):
if sys.version_info >= (3, 10):
__match_args__ = ("id", "ctx")
id: _identifier
id: _Identifier
ctx: expr_context

class List(expr):
Expand Down Expand Up @@ -479,7 +479,7 @@ class ExceptHandler(excepthandler):
if sys.version_info >= (3, 10):
__match_args__ = ("type", "name", "body")
type: expr | None
name: _identifier | None
name: _Identifier | None
body: list[stmt]

class arguments(AST):
Expand All @@ -497,20 +497,20 @@ class arguments(AST):
class arg(AST):
if sys.version_info >= (3, 10):
__match_args__ = ("arg", "annotation", "type_comment")
arg: _identifier
arg: _Identifier
annotation: expr | None

class keyword(AST):
if sys.version_info >= (3, 10):
__match_args__ = ("arg", "value")
arg: _identifier | None
arg: _Identifier | None
value: expr

class alias(AST):
if sys.version_info >= (3, 10):
__match_args__ = ("name", "asname")
name: _identifier
asname: _identifier | None
name: _Identifier
asname: _Identifier | None

class withitem(AST):
if sys.version_info >= (3, 10):
Expand All @@ -526,11 +526,11 @@ if sys.version_info >= (3, 10):

class pattern(AST): ...
# Without the alias, Pyright complains variables named pattern are recursively defined
_pattern: TypeAlias = pattern
_Pattern: TypeAlias = pattern

class match_case(AST):
__match_args__ = ("pattern", "guard", "body")
pattern: _pattern
pattern: _Pattern
guard: expr | None
body: list[stmt]

Expand All @@ -548,25 +548,25 @@ if sys.version_info >= (3, 10):

class MatchStar(pattern):
__match_args__ = ("name",)
name: _identifier | None
name: _Identifier | None

class MatchMapping(pattern):
__match_args__ = ("keys", "patterns", "rest")
keys: list[expr]
patterns: list[pattern]
rest: _identifier | None
rest: _Identifier | None

class MatchClass(pattern):
__match_args__ = ("cls", "patterns", "kwd_attrs", "kwd_patterns")
cls: expr
patterns: list[pattern]
kwd_attrs: list[_identifier]
kwd_attrs: list[_Identifier]
kwd_patterns: list[pattern]

class MatchAs(pattern):
__match_args__ = ("pattern", "name")
pattern: _pattern | None
name: _identifier | None
pattern: _Pattern | None
name: _Identifier | None

class MatchOr(pattern):
__match_args__ = ("patterns",)
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from typing_extensions import Literal, TypeAlias
class _EncodingMap:
def size(self) -> int: ...

_MapT: TypeAlias = dict[int, int] | _EncodingMap
_CharMap: TypeAlias = dict[int, int] | _EncodingMap
_Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]]
_SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None]

Expand Down Expand Up @@ -66,11 +66,11 @@ def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) -
@overload
def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ...
def lookup(__encoding: str) -> codecs.CodecInfo: ...
def charmap_build(__map: str) -> _MapT: ...
def charmap_build(__map: str) -> _CharMap: ...
def ascii_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ...
def ascii_encode(__str: str, __errors: str | None = ...) -> tuple[bytes, int]: ...
def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[str, int]: ...
def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[bytes, int]: ...
def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[str, int]: ...
def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[bytes, int]: ...
def escape_decode(__data: str | bytes, __errors: str | None = ...) -> tuple[str, int]: ...
def escape_encode(__data: bytes, __errors: str | None = ...) -> tuple[bytes, int]: ...
def latin_1_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ...
Expand Down
46 changes: 23 additions & 23 deletions mypy/typeshed/stdlib/_curses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from typing import IO, Any, NamedTuple, overload
from typing_extensions import TypeAlias, final

if sys.platform != "win32":
_chtype: TypeAlias = str | bytes | int
_ChType: TypeAlias = str | bytes | int

# ACS codes are only initialized after initscr is called
ACS_BBSS: int
Expand Down Expand Up @@ -365,9 +365,9 @@ if sys.platform != "win32":
__i9: int = ...,
) -> bytes: ...
def typeahead(__fd: int) -> None: ...
def unctrl(__ch: _chtype) -> bytes: ...
def unctrl(__ch: _ChType) -> bytes: ...
def unget_wch(__ch: int | str) -> None: ...
def ungetch(__ch: _chtype) -> None: ...
def ungetch(__ch: _ChType) -> None: ...
def ungetmouse(__id: int, __x: int, __y: int, __z: int, __bstate: int) -> None: ...
def update_lines_cols() -> None: ...
def use_default_colors() -> None: ...
Expand All @@ -379,9 +379,9 @@ if sys.platform != "win32":
class _CursesWindow:
encoding: str
@overload
def addch(self, ch: _chtype, attr: int = ...) -> None: ...
def addch(self, ch: _ChType, attr: int = ...) -> None: ...
@overload
def addch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ...
def addch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ...
@overload
def addnstr(self, str: str, n: int, attr: int = ...) -> None: ...
@overload
Expand All @@ -393,23 +393,23 @@ if sys.platform != "win32":
def attroff(self, __attr: int) -> None: ...
def attron(self, __attr: int) -> None: ...
def attrset(self, __attr: int) -> None: ...
def bkgd(self, __ch: _chtype, __attr: int = ...) -> None: ...
def bkgdset(self, __ch: _chtype, __attr: int = ...) -> None: ...
def bkgd(self, __ch: _ChType, __attr: int = ...) -> None: ...
def bkgdset(self, __ch: _ChType, __attr: int = ...) -> None: ...
def border(
self,
ls: _chtype = ...,
rs: _chtype = ...,
ts: _chtype = ...,
bs: _chtype = ...,
tl: _chtype = ...,
tr: _chtype = ...,
bl: _chtype = ...,
br: _chtype = ...,
ls: _ChType = ...,
rs: _ChType = ...,
ts: _ChType = ...,
bs: _ChType = ...,
tl: _ChType = ...,
tr: _ChType = ...,
bl: _ChType = ...,
br: _ChType = ...,
) -> None: ...
@overload
def box(self) -> None: ...
@overload
def box(self, vertch: _chtype = ..., horch: _chtype = ...) -> None: ...
def box(self, vertch: _ChType = ..., horch: _ChType = ...) -> None: ...
@overload
def chgat(self, attr: int) -> None: ...
@overload
Expand All @@ -432,7 +432,7 @@ if sys.platform != "win32":
def derwin(self, begin_y: int, begin_x: int) -> _CursesWindow: ...
@overload
def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> _CursesWindow: ...
def echochar(self, __ch: _chtype, __attr: int = ...) -> None: ...
def echochar(self, __ch: _ChType, __attr: int = ...) -> None: ...
def enclose(self, __y: int, __x: int) -> bool: ...
def erase(self) -> None: ...
def getbegyx(self) -> tuple[int, int]: ...
Expand Down Expand Up @@ -461,9 +461,9 @@ if sys.platform != "win32":
def getstr(self, y: int, x: int, n: int) -> bytes: ...
def getyx(self) -> tuple[int, int]: ...
@overload
def hline(self, ch: _chtype, n: int) -> None: ...
def hline(self, ch: _ChType, n: int) -> None: ...
@overload
def hline(self, y: int, x: int, ch: _chtype, n: int) -> None: ...
def hline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
def idcok(self, flag: bool) -> None: ...
def idlok(self, yes: bool) -> None: ...
def immedok(self, flag: bool) -> None: ...
Expand All @@ -472,9 +472,9 @@ if sys.platform != "win32":
@overload
def inch(self, y: int, x: int) -> int: ...
@overload
def insch(self, ch: _chtype, attr: int = ...) -> None: ...
def insch(self, ch: _ChType, attr: int = ...) -> None: ...
@overload
def insch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ...
def insch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ...
def insdelln(self, nlines: int) -> None: ...
def insertln(self) -> None: ...
@overload
Expand Down Expand Up @@ -543,9 +543,9 @@ if sys.platform != "win32":
def touchwin(self) -> None: ...
def untouchwin(self) -> None: ...
@overload
def vline(self, ch: _chtype, n: int) -> None: ...
def vline(self, ch: _ChType, n: int) -> None: ...
@overload
def vline(self, y: int, x: int, ch: _chtype, n: int) -> None: ...
def vline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
if sys.version_info >= (3, 8):
class _ncurses_version(NamedTuple):
major: int
Expand Down
5 changes: 3 additions & 2 deletions mypy/typeshed/stdlib/_decimal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sys
from _typeshed import Self
from collections.abc import Container, Sequence
from types import TracebackType
from typing import Any, NamedTuple, Union, overload
from typing import Any, ClassVar, NamedTuple, Union, overload
from typing_extensions import TypeAlias

_Decimal: TypeAlias = Decimal | int
Expand Down Expand Up @@ -209,7 +209,8 @@ class Context:
def clear_traps(self) -> None: ...
def copy(self) -> Context: ...
def __copy__(self) -> Context: ...
__hash__: Any
# see https://github.com/python/cpython/issues/94107
__hash__: ClassVar[None] # type: ignore[assignment]
def Etiny(self) -> int: ...
def Etop(self) -> int: ...
def create_decimal(self, __num: _DecimalNew = ...) -> Decimal: ...
Expand Down
Loading

0 comments on commit 3ae19a2

Please sign in to comment.