Skip to content

Commit

Permalink
Sync typeshed (python#12663)
Browse files Browse the repository at this point in the history
* Sync typeshed

Source commit:
python/typeshed@5dad506

* Fix tests

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored Apr 23, 2022
1 parent d1c0616 commit 40bbfb5
Show file tree
Hide file tree
Showing 289 changed files with 2,086 additions and 1,454 deletions.
2 changes: 1 addition & 1 deletion mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ def test_config_file(self) -> None:
output = run_stubtest(stub=stub, runtime=runtime, options=[])
assert remove_color_code(output) == (
"error: test_module.temp variable differs from runtime type Literal[5]\n"
"Stub: at line 2\ndecimal.Decimal\nRuntime:\n5\n\n"
"Stub: at line 2\n_decimal.Decimal\nRuntime:\n5\n\n"
)
output = run_stubtest(stub=stub, runtime=runtime, options=[], config_file=config_file)
assert output == ""
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ webbrowser: 2.7-
winreg: 3.0-
winsound: 2.7-
wsgiref: 2.7-
wsgiref.types: 3.11-
xdrlib: 2.7-
xml: 2.7-
xmlrpc: 3.0-
Expand Down
18 changes: 13 additions & 5 deletions mypy/typeshed/stdlib/_ast.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys
from typing import Any, ClassVar
from typing_extensions import Literal
from typing_extensions import Literal, TypeAlias

PyCF_ONLY_AST: Literal[1024]
if sys.version_info >= (3, 8):
PyCF_TYPE_COMMENTS: Literal[4096]
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]

_identifier = str
_identifier: TypeAlias = str

class AST:
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -172,6 +172,14 @@ class Try(stmt):
orelse: list[stmt]
finalbody: list[stmt]

if sys.version_info >= (3, 11):
class TryStar(stmt):
__match_args__ = ("body", "handlers", "orelse", "finalbody")
body: list[stmt]
handlers: list[ExceptHandler]
orelse: list[stmt]
finalbody: list[stmt]

class Assert(stmt):
if sys.version_info >= (3, 10):
__match_args__ = ("test", "msg")
Expand Down Expand Up @@ -358,10 +366,10 @@ class Attribute(expr):
ctx: expr_context

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

class Slice(_SliceT):
if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -516,7 +524,7 @@ if sys.version_info >= (3, 10):

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

class match_case(AST):
__match_args__ = ("pattern", "guard", "body")
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/_bisect.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from _typeshed import SupportsRichComparisonT
from typing import Callable, MutableSequence, Sequence, TypeVar, overload
from collections.abc import Callable, MutableSequence, Sequence
from typing import TypeVar, overload

_T = TypeVar("_T")

Expand Down
8 changes: 5 additions & 3 deletions mypy/typeshed/stdlib/_codecs.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import codecs
import sys
from typing import Any, Callable
from collections.abc import Callable
from typing import Any
from typing_extensions import TypeAlias

# This type is not exposed; it is defined in unicodeobject.c
class _EncodingMap:
def size(self) -> int: ...

_MapT = dict[int, int] | _EncodingMap
_Handler = Callable[[Exception], tuple[str, int]]
_MapT: TypeAlias = dict[int, int] | _EncodingMap
_Handler: TypeAlias = Callable[[Exception], tuple[str, int]]

def register(__search_function: Callable[[str], Any]) -> None: ...
def register_error(__errors: str, __handler: _Handler) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from types import MappingProxyType
from typing import (
from typing import ( # noqa: Y027,Y038
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/_compression.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import WriteableBuffer
from collections.abc import Callable
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
from typing import Any, Callable, Protocol
from typing import Any, Protocol

BUFFER_SIZE = DEFAULT_BUFFER_SIZE

Expand Down
7 changes: 4 additions & 3 deletions mypy/typeshed/stdlib/_csv.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Iterable, Iterator, Protocol, Union
from typing_extensions import Literal
from collections.abc import Iterable, Iterator
from typing import Any, Protocol, Union
from typing_extensions import Literal, TypeAlias

__version__: str

Expand All @@ -21,7 +22,7 @@ class Dialect:
strict: int
def __init__(self) -> None: ...

_DialectLike = Union[str, Dialect, type[Dialect]]
_DialectLike: TypeAlias = Union[str, Dialect, type[Dialect]]

class _reader(Iterator[list[str]]):
dialect: Dialect
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_curses.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
from _typeshed import SupportsRead
from typing import IO, Any, NamedTuple, overload
from typing_extensions import final
from typing_extensions import TypeAlias, final

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

# ACS codes are only initialized after initscr is called
ACS_BBSS: int
Expand Down
Loading

0 comments on commit 40bbfb5

Please sign in to comment.