Skip to content

Commit 3ae19a2

Browse files
authored
Sync typeshed (#13097)
Source commit: python/typeshed@b145b32 This reapplies #13093. This will likely be the last sync that still has support for Python 3.6.
1 parent 256f1f3 commit 3ae19a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2777
-1239
lines changed

mypy/config_parser.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
else:
1212
import tomli as tomllib
1313

14-
from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence,
15-
TextIO, Tuple, Union)
14+
from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence,
15+
TextIO, Tuple, Union, Iterable)
1616
from typing_extensions import Final, TypeAlias as _TypeAlias
1717

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

184185
config_parser = configparser.RawConfigParser()
185186

mypy/typeshed/stdlib/@python2/itertools.pyi

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ class chain(Iterator[_T], Generic[_T]):
2222

2323
def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ...
2424
def dropwhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
25-
def ifilter(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ...
25+
@overload
26+
def ifilter(predicate: None, iterable: Iterable[_T | None]) -> Iterator[_T]: ...
27+
@overload
28+
def ifilter(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ...
2629
def ifilterfalse(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ...
2730
@overload
2831
def groupby(iterable: Iterable[_T], key: None = ...) -> Iterator[tuple[_T, Iterator[_T]]]: ...

mypy/typeshed/stdlib/__future__.pyi

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import sys
2+
from typing_extensions import TypeAlias
3+
4+
_VersionInfo: TypeAlias = tuple[int, int, int, str, int]
25

36
class _Feature:
4-
def __init__(self, optionalRelease: sys._version_info, mandatoryRelease: sys._version_info, compiler_flag: int) -> None: ...
5-
def getOptionalRelease(self) -> sys._version_info: ...
6-
def getMandatoryRelease(self) -> sys._version_info: ...
7+
def __init__(self, optionalRelease: _VersionInfo, mandatoryRelease: _VersionInfo | None, compiler_flag: int) -> None: ...
8+
def getOptionalRelease(self) -> _VersionInfo: ...
9+
def getMandatoryRelease(self) -> _VersionInfo | None: ...
710
compiler_flag: int
811

912
absolute_import: _Feature

mypy/typeshed/stdlib/_ast.pyi

+25-25
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if sys.version_info >= (3, 8):
77
PyCF_TYPE_COMMENTS: Literal[4096]
88
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
99

10-
_identifier: TypeAlias = str
10+
_Identifier: TypeAlias = str
1111

1212
class AST:
1313
if sys.version_info >= (3, 10):
@@ -61,7 +61,7 @@ class stmt(AST): ...
6161
class FunctionDef(stmt):
6262
if sys.version_info >= (3, 10):
6363
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
64-
name: _identifier
64+
name: _Identifier
6565
args: arguments
6666
body: list[stmt]
6767
decorator_list: list[expr]
@@ -70,7 +70,7 @@ class FunctionDef(stmt):
7070
class AsyncFunctionDef(stmt):
7171
if sys.version_info >= (3, 10):
7272
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
73-
name: _identifier
73+
name: _Identifier
7474
args: arguments
7575
body: list[stmt]
7676
decorator_list: list[expr]
@@ -79,7 +79,7 @@ class AsyncFunctionDef(stmt):
7979
class ClassDef(stmt):
8080
if sys.version_info >= (3, 10):
8181
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list")
82-
name: _identifier
82+
name: _Identifier
8383
bases: list[expr]
8484
keywords: list[keyword]
8585
body: list[stmt]
@@ -194,19 +194,19 @@ class Import(stmt):
194194
class ImportFrom(stmt):
195195
if sys.version_info >= (3, 10):
196196
__match_args__ = ("module", "names", "level")
197-
module: _identifier | None
197+
module: _Identifier | None
198198
names: list[alias]
199199
level: int
200200

201201
class Global(stmt):
202202
if sys.version_info >= (3, 10):
203203
__match_args__ = ("names",)
204-
names: list[_identifier]
204+
names: list[_Identifier]
205205

206206
class Nonlocal(stmt):
207207
if sys.version_info >= (3, 10):
208208
__match_args__ = ("names",)
209-
names: list[_identifier]
209+
names: list[_Identifier]
210210

211211
class Expr(stmt):
212212
if sys.version_info >= (3, 10):
@@ -362,16 +362,16 @@ class Attribute(expr):
362362
if sys.version_info >= (3, 10):
363363
__match_args__ = ("value", "attr", "ctx")
364364
value: expr
365-
attr: _identifier
365+
attr: _Identifier
366366
ctx: expr_context
367367

368368
if sys.version_info >= (3, 9):
369-
_SliceT: TypeAlias = expr
369+
_Slice: TypeAlias = expr
370370
else:
371371
class slice(AST): ...
372-
_SliceT: TypeAlias = slice
372+
_Slice: TypeAlias = slice
373373

374-
class Slice(_SliceT):
374+
class Slice(_Slice):
375375
if sys.version_info >= (3, 10):
376376
__match_args__ = ("lower", "upper", "step")
377377
lower: expr | None
@@ -389,7 +389,7 @@ class Subscript(expr):
389389
if sys.version_info >= (3, 10):
390390
__match_args__ = ("value", "slice", "ctx")
391391
value: expr
392-
slice: _SliceT
392+
slice: _Slice
393393
ctx: expr_context
394394

395395
class Starred(expr):
@@ -401,7 +401,7 @@ class Starred(expr):
401401
class Name(expr):
402402
if sys.version_info >= (3, 10):
403403
__match_args__ = ("id", "ctx")
404-
id: _identifier
404+
id: _Identifier
405405
ctx: expr_context
406406

407407
class List(expr):
@@ -479,7 +479,7 @@ class ExceptHandler(excepthandler):
479479
if sys.version_info >= (3, 10):
480480
__match_args__ = ("type", "name", "body")
481481
type: expr | None
482-
name: _identifier | None
482+
name: _Identifier | None
483483
body: list[stmt]
484484

485485
class arguments(AST):
@@ -497,20 +497,20 @@ class arguments(AST):
497497
class arg(AST):
498498
if sys.version_info >= (3, 10):
499499
__match_args__ = ("arg", "annotation", "type_comment")
500-
arg: _identifier
500+
arg: _Identifier
501501
annotation: expr | None
502502

503503
class keyword(AST):
504504
if sys.version_info >= (3, 10):
505505
__match_args__ = ("arg", "value")
506-
arg: _identifier | None
506+
arg: _Identifier | None
507507
value: expr
508508

509509
class alias(AST):
510510
if sys.version_info >= (3, 10):
511511
__match_args__ = ("name", "asname")
512-
name: _identifier
513-
asname: _identifier | None
512+
name: _Identifier
513+
asname: _Identifier | None
514514

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

527527
class pattern(AST): ...
528528
# Without the alias, Pyright complains variables named pattern are recursively defined
529-
_pattern: TypeAlias = pattern
529+
_Pattern: TypeAlias = pattern
530530

531531
class match_case(AST):
532532
__match_args__ = ("pattern", "guard", "body")
533-
pattern: _pattern
533+
pattern: _Pattern
534534
guard: expr | None
535535
body: list[stmt]
536536

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

549549
class MatchStar(pattern):
550550
__match_args__ = ("name",)
551-
name: _identifier | None
551+
name: _Identifier | None
552552

553553
class MatchMapping(pattern):
554554
__match_args__ = ("keys", "patterns", "rest")
555555
keys: list[expr]
556556
patterns: list[pattern]
557-
rest: _identifier | None
557+
rest: _Identifier | None
558558

559559
class MatchClass(pattern):
560560
__match_args__ = ("cls", "patterns", "kwd_attrs", "kwd_patterns")
561561
cls: expr
562562
patterns: list[pattern]
563-
kwd_attrs: list[_identifier]
563+
kwd_attrs: list[_Identifier]
564564
kwd_patterns: list[pattern]
565565

566566
class MatchAs(pattern):
567567
__match_args__ = ("pattern", "name")
568-
pattern: _pattern | None
569-
name: _identifier | None
568+
pattern: _Pattern | None
569+
name: _Identifier | None
570570

571571
class MatchOr(pattern):
572572
__match_args__ = ("patterns",)

mypy/typeshed/stdlib/_codecs.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from typing_extensions import Literal, TypeAlias
88
class _EncodingMap:
99
def size(self) -> int: ...
1010

11-
_MapT: TypeAlias = dict[int, int] | _EncodingMap
11+
_CharMap: TypeAlias = dict[int, int] | _EncodingMap
1212
_Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]]
1313
_SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None]
1414

@@ -66,11 +66,11 @@ def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) -
6666
@overload
6767
def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ...
6868
def lookup(__encoding: str) -> codecs.CodecInfo: ...
69-
def charmap_build(__map: str) -> _MapT: ...
69+
def charmap_build(__map: str) -> _CharMap: ...
7070
def ascii_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ...
7171
def ascii_encode(__str: str, __errors: str | None = ...) -> tuple[bytes, int]: ...
72-
def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[str, int]: ...
73-
def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[bytes, int]: ...
72+
def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[str, int]: ...
73+
def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[bytes, int]: ...
7474
def escape_decode(__data: str | bytes, __errors: str | None = ...) -> tuple[str, int]: ...
7575
def escape_encode(__data: bytes, __errors: str | None = ...) -> tuple[bytes, int]: ...
7676
def latin_1_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ...

mypy/typeshed/stdlib/_curses.pyi

+23-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from typing import IO, Any, NamedTuple, overload
44
from typing_extensions import TypeAlias, final
55

66
if sys.platform != "win32":
7-
_chtype: TypeAlias = str | bytes | int
7+
_ChType: TypeAlias = str | bytes | int
88

99
# ACS codes are only initialized after initscr is called
1010
ACS_BBSS: int
@@ -365,9 +365,9 @@ if sys.platform != "win32":
365365
__i9: int = ...,
366366
) -> bytes: ...
367367
def typeahead(__fd: int) -> None: ...
368-
def unctrl(__ch: _chtype) -> bytes: ...
368+
def unctrl(__ch: _ChType) -> bytes: ...
369369
def unget_wch(__ch: int | str) -> None: ...
370-
def ungetch(__ch: _chtype) -> None: ...
370+
def ungetch(__ch: _ChType) -> None: ...
371371
def ungetmouse(__id: int, __x: int, __y: int, __z: int, __bstate: int) -> None: ...
372372
def update_lines_cols() -> None: ...
373373
def use_default_colors() -> None: ...
@@ -379,9 +379,9 @@ if sys.platform != "win32":
379379
class _CursesWindow:
380380
encoding: str
381381
@overload
382-
def addch(self, ch: _chtype, attr: int = ...) -> None: ...
382+
def addch(self, ch: _ChType, attr: int = ...) -> None: ...
383383
@overload
384-
def addch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ...
384+
def addch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ...
385385
@overload
386386
def addnstr(self, str: str, n: int, attr: int = ...) -> None: ...
387387
@overload
@@ -393,23 +393,23 @@ if sys.platform != "win32":
393393
def attroff(self, __attr: int) -> None: ...
394394
def attron(self, __attr: int) -> None: ...
395395
def attrset(self, __attr: int) -> None: ...
396-
def bkgd(self, __ch: _chtype, __attr: int = ...) -> None: ...
397-
def bkgdset(self, __ch: _chtype, __attr: int = ...) -> None: ...
396+
def bkgd(self, __ch: _ChType, __attr: int = ...) -> None: ...
397+
def bkgdset(self, __ch: _ChType, __attr: int = ...) -> None: ...
398398
def border(
399399
self,
400-
ls: _chtype = ...,
401-
rs: _chtype = ...,
402-
ts: _chtype = ...,
403-
bs: _chtype = ...,
404-
tl: _chtype = ...,
405-
tr: _chtype = ...,
406-
bl: _chtype = ...,
407-
br: _chtype = ...,
400+
ls: _ChType = ...,
401+
rs: _ChType = ...,
402+
ts: _ChType = ...,
403+
bs: _ChType = ...,
404+
tl: _ChType = ...,
405+
tr: _ChType = ...,
406+
bl: _ChType = ...,
407+
br: _ChType = ...,
408408
) -> None: ...
409409
@overload
410410
def box(self) -> None: ...
411411
@overload
412-
def box(self, vertch: _chtype = ..., horch: _chtype = ...) -> None: ...
412+
def box(self, vertch: _ChType = ..., horch: _ChType = ...) -> None: ...
413413
@overload
414414
def chgat(self, attr: int) -> None: ...
415415
@overload
@@ -432,7 +432,7 @@ if sys.platform != "win32":
432432
def derwin(self, begin_y: int, begin_x: int) -> _CursesWindow: ...
433433
@overload
434434
def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> _CursesWindow: ...
435-
def echochar(self, __ch: _chtype, __attr: int = ...) -> None: ...
435+
def echochar(self, __ch: _ChType, __attr: int = ...) -> None: ...
436436
def enclose(self, __y: int, __x: int) -> bool: ...
437437
def erase(self) -> None: ...
438438
def getbegyx(self) -> tuple[int, int]: ...
@@ -461,9 +461,9 @@ if sys.platform != "win32":
461461
def getstr(self, y: int, x: int, n: int) -> bytes: ...
462462
def getyx(self) -> tuple[int, int]: ...
463463
@overload
464-
def hline(self, ch: _chtype, n: int) -> None: ...
464+
def hline(self, ch: _ChType, n: int) -> None: ...
465465
@overload
466-
def hline(self, y: int, x: int, ch: _chtype, n: int) -> None: ...
466+
def hline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
467467
def idcok(self, flag: bool) -> None: ...
468468
def idlok(self, yes: bool) -> None: ...
469469
def immedok(self, flag: bool) -> None: ...
@@ -472,9 +472,9 @@ if sys.platform != "win32":
472472
@overload
473473
def inch(self, y: int, x: int) -> int: ...
474474
@overload
475-
def insch(self, ch: _chtype, attr: int = ...) -> None: ...
475+
def insch(self, ch: _ChType, attr: int = ...) -> None: ...
476476
@overload
477-
def insch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ...
477+
def insch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ...
478478
def insdelln(self, nlines: int) -> None: ...
479479
def insertln(self) -> None: ...
480480
@overload
@@ -543,9 +543,9 @@ if sys.platform != "win32":
543543
def touchwin(self) -> None: ...
544544
def untouchwin(self) -> None: ...
545545
@overload
546-
def vline(self, ch: _chtype, n: int) -> None: ...
546+
def vline(self, ch: _ChType, n: int) -> None: ...
547547
@overload
548-
def vline(self, y: int, x: int, ch: _chtype, n: int) -> None: ...
548+
def vline(self, y: int, x: int, ch: _ChType, n: int) -> None: ...
549549
if sys.version_info >= (3, 8):
550550
class _ncurses_version(NamedTuple):
551551
major: int

mypy/typeshed/stdlib/_decimal.pyi

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
from _typeshed import Self
44
from collections.abc import Container, Sequence
55
from types import TracebackType
6-
from typing import Any, NamedTuple, Union, overload
6+
from typing import Any, ClassVar, NamedTuple, Union, overload
77
from typing_extensions import TypeAlias
88

99
_Decimal: TypeAlias = Decimal | int
@@ -209,7 +209,8 @@ class Context:
209209
def clear_traps(self) -> None: ...
210210
def copy(self) -> Context: ...
211211
def __copy__(self) -> Context: ...
212-
__hash__: Any
212+
# see https://github.com/python/cpython/issues/94107
213+
__hash__: ClassVar[None] # type: ignore[assignment]
213214
def Etiny(self) -> int: ...
214215
def Etop(self) -> int: ...
215216
def create_decimal(self, __num: _DecimalNew = ...) -> Decimal: ...

0 commit comments

Comments
 (0)