Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync typeshed #14375

Merged
merged 4 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/_winapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ if sys.platform == "win32":
def PeekNamedPipe(__handle: int, __size: int = ...) -> tuple[int, int] | tuple[bytes, int, int]: ...
if sys.version_info >= (3, 10):
def LCMapStringEx(locale: str, flags: int, src: str) -> str: ...
def UnmapViewOfFile(__address: int) -> None: ...

@overload
def ReadFile(handle: int, size: int, overlapped: Literal[True]) -> tuple[Overlapped, int]: ...
Expand Down
16 changes: 15 additions & 1 deletion mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class NodeVisitor:
def visit_Constant(self, node: Constant) -> Any: ...
if sys.version_info >= (3, 8):
def visit_NamedExpr(self, node: NamedExpr) -> Any: ...
def visit_TypeIgnore(self, node: TypeIgnore) -> Any: ...

def visit_Attribute(self, node: Attribute) -> Any: ...
def visit_Subscript(self, node: Subscript) -> Any: ...
Expand Down Expand Up @@ -135,6 +136,19 @@ class NodeVisitor:
def visit_keyword(self, node: keyword) -> Any: ...
def visit_alias(self, node: alias) -> Any: ...
def visit_withitem(self, node: withitem) -> Any: ...
if sys.version_info >= (3, 10):
def visit_Match(self, node: Match) -> Any: ...
def visit_MatchValue(self, node: MatchValue) -> Any: ...
def visit_MatchSequence(self, node: MatchSequence) -> Any: ...
def visit_MatchStar(self, node: MatchStar) -> Any: ...
def visit_MatchMapping(self, node: MatchMapping) -> Any: ...
def visit_MatchClass(self, node: MatchClass) -> Any: ...
def visit_MatchAs(self, node: MatchAs) -> Any: ...
def visit_MatchOr(self, node: MatchOr) -> Any: ...

if sys.version_info >= (3, 11):
def visit_TryStar(self, node: TryStar) -> Any: ...

# visit methods for deprecated nodes
def visit_ExtSlice(self, node: ExtSlice) -> Any: ...
def visit_Index(self, node: Index) -> Any: ...
Expand Down Expand Up @@ -261,7 +275,7 @@ else:
def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ...

def fix_missing_locations(node: _T) -> _T: ...
def get_docstring(node: AST, clean: bool = ...) -> str | None: ...
def get_docstring(node: AsyncFunctionDef | FunctionDef | ClassDef | Module, clean: bool = ...) -> str | None: ...
def increment_lineno(node: _T, n: int = ...) -> _T: ...
def iter_child_nodes(node: AST) -> Iterator[AST]: ...
def iter_fields(node: AST) -> Iterator[tuple[str, Any]]: ...
Expand Down
98 changes: 91 additions & 7 deletions mypy/typeshed/stdlib/asyncio/subprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import subprocess
import sys
from _typeshed import StrOrBytesPath
from asyncio import events, protocols, streams, transports
from collections.abc import Callable
from collections.abc import Callable, Collection
from typing import IO, Any
from typing_extensions import Literal, TypeAlias

Expand Down Expand Up @@ -40,7 +40,7 @@ class Process:
def kill(self) -> None: ...
async def communicate(self, input: bytes | bytearray | memoryview | None = ...) -> tuple[bytes, bytes]: ...

if sys.version_info >= (3, 10):
if sys.version_info >= (3, 11):
async def create_subprocess_shell(
cmd: str | bytes,
stdin: int | IO[Any] | None = ...,
Expand All @@ -65,7 +65,13 @@ if sys.version_info >= (3, 10):
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
pass_fds: Collection[int] = ...,
group: None | str | int = ...,
extra_groups: None | Collection[str | int] = ...,
user: None | str | int = ...,
umask: int = ...,
process_group: int | None = ...,
pipesize: int = ...,
) -> Process: ...
async def create_subprocess_exec(
program: _ExecArg,
Expand All @@ -91,10 +97,80 @@ if sys.version_info >= (3, 10):
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
pass_fds: Collection[int] = ...,
group: None | str | int = ...,
extra_groups: None | Collection[str | int] = ...,
user: None | str | int = ...,
umask: int = ...,
process_group: int | None = ...,
pipesize: int = ...,
) -> Process: ...

else:
elif sys.version_info >= (3, 10):
async def create_subprocess_shell(
cmd: str | bytes,
stdin: int | IO[Any] | None = ...,
stdout: int | IO[Any] | None = ...,
stderr: int | IO[Any] | None = ...,
limit: int = ...,
*,
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
universal_newlines: Literal[False] = ...,
shell: Literal[True] = ...,
bufsize: Literal[0] = ...,
encoding: None = ...,
errors: None = ...,
text: Literal[False, None] = ...,
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
executable: StrOrBytesPath | None = ...,
preexec_fn: Callable[[], Any] | None = ...,
close_fds: bool = ...,
cwd: StrOrBytesPath | None = ...,
env: subprocess._ENV | None = ...,
startupinfo: Any | None = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Collection[int] = ...,
group: None | str | int = ...,
extra_groups: None | Collection[str | int] = ...,
user: None | str | int = ...,
umask: int = ...,
pipesize: int = ...,
) -> Process: ...
async def create_subprocess_exec(
program: _ExecArg,
*args: _ExecArg,
stdin: int | IO[Any] | None = ...,
stdout: int | IO[Any] | None = ...,
stderr: int | IO[Any] | None = ...,
limit: int = ...,
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
universal_newlines: Literal[False] = ...,
shell: Literal[True] = ...,
bufsize: Literal[0] = ...,
encoding: None = ...,
errors: None = ...,
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
text: bool | None = ...,
executable: StrOrBytesPath | None = ...,
preexec_fn: Callable[[], Any] | None = ...,
close_fds: bool = ...,
cwd: StrOrBytesPath | None = ...,
env: subprocess._ENV | None = ...,
startupinfo: Any | None = ...,
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Collection[int] = ...,
group: None | str | int = ...,
extra_groups: None | Collection[str | int] = ...,
user: None | str | int = ...,
umask: int = ...,
pipesize: int = ...,
) -> Process: ...

else: # >= 3.9
async def create_subprocess_shell(
cmd: str | bytes,
stdin: int | IO[Any] | None = ...,
Expand All @@ -120,7 +196,11 @@ else:
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
pass_fds: Collection[int] = ...,
group: None | str | int = ...,
extra_groups: None | Collection[str | int] = ...,
user: None | str | int = ...,
umask: int = ...,
) -> Process: ...
async def create_subprocess_exec(
program: _ExecArg,
Expand All @@ -147,5 +227,9 @@ else:
creationflags: int = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Any = ...,
pass_fds: Collection[int] = ...,
group: None | str | int = ...,
extra_groups: None | Collection[str | int] = ...,
user: None | str | int = ...,
umask: int = ...,
) -> Process: ...
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ else:
# While this is true in general, here it's sort-of okay to have a covariant subclass,
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
# and `asyncio.Task.set_result()` always raises.
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var]
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
if sys.version_info >= (3, 8):
def __init__(
self,
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ast
import sys
import types
from _ast import AST
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import (
AnyStr_co,
Expand Down Expand Up @@ -1096,7 +1096,7 @@ class property:
class _NotImplementedType(Any): # type: ignore[misc]
# A little weird, but typing the __call__ as NotImplemented makes the error message
# for NotImplemented() much better
__call__: NotImplemented # type: ignore[valid-type]
__call__: NotImplemented # type: ignore[valid-type] # pyright: ignore[reportGeneralTypeIssues]

NotImplemented: _NotImplementedType

Expand Down Expand Up @@ -1131,7 +1131,7 @@ if sys.version_info >= (3, 10):
# TODO: `compile` has a more precise return type in reality; work on a way of expressing that?
if sys.version_info >= (3, 8):
def compile(
source: str | ReadableBuffer | AST,
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
filename: str | ReadableBuffer | _PathLike[Any],
mode: str,
flags: int = ...,
Expand All @@ -1143,7 +1143,7 @@ if sys.version_info >= (3, 8):

else:
def compile(
source: str | ReadableBuffer | AST,
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
filename: str | ReadableBuffer | _PathLike[Any],
mode: str,
flags: int = ...,
Expand Down
7 changes: 4 additions & 3 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,17 @@ class _OrderedDictValuesView(ValuesView[_VT_co], Reversible[_VT_co]):
# The C implementations of the "views" classes
# (At runtime, these are called `odict_keys`, `odict_items` and `odict_values`,
# but they are not exposed anywhere)
# pyright doesn't have a specific error code for subclassing error!
@final
class _odict_keys(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc]
class _odict_keys(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc] # pyright: ignore
def __reversed__(self) -> Iterator[_KT_co]: ...

@final
class _odict_items(dict_items[_KT_co, _VT_co], Reversible[tuple[_KT_co, _VT_co]]): # type: ignore[misc]
class _odict_items(dict_items[_KT_co, _VT_co], Reversible[tuple[_KT_co, _VT_co]]): # type: ignore[misc] # pyright: ignore
def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ...

@final
class _odict_values(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT_co, _VT_co]): # type: ignore[misc]
class _odict_values(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore
def __reversed__(self) -> Iterator[_VT_co]: ...

class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class _CDataMeta(type):
# By default mypy complains about the following two methods, because strictly speaking cls
# might not be a Type[_CT]. However this can never actually happen, because the only class that
# uses _CDataMeta as its metaclass is _CData. So it's safe to ignore the errors here.
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc]
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc]
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]

class _CData(metaclass=_CDataMeta):
_b_base: int
Expand Down
33 changes: 26 additions & 7 deletions mypy/typeshed/stdlib/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ class date:
@property
def day(self) -> int: ...
def ctime(self) -> str: ...
def strftime(self, __format: str) -> str: ...
# On <3.12, the name of the parameter in the pure-Python implementation
# didn't match the name in the C implementation,
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
if sys.version_info >= (3, 12):
def strftime(self, format: str) -> str: ...
else:
def strftime(self, __format: str) -> str: ...

def __format__(self, __fmt: str) -> str: ...
def isoformat(self) -> str: ...
def timetuple(self) -> struct_time: ...
Expand Down Expand Up @@ -140,7 +147,14 @@ class time:
def isoformat(self, timespec: str = ...) -> str: ...
@classmethod
def fromisoformat(cls: type[Self], __time_string: str) -> Self: ...
def strftime(self, __format: str) -> str: ...
# On <3.12, the name of the parameter in the pure-Python implementation
# didn't match the name in the C implementation,
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
if sys.version_info >= (3, 12):
def strftime(self, format: str) -> str: ...
else:
def strftime(self, __format: str) -> str: ...

def __format__(self, __fmt: str) -> str: ...
def utcoffset(self) -> timedelta | None: ...
def tzname(self) -> str | None: ...
Expand Down Expand Up @@ -233,11 +247,16 @@ class datetime(date):
def tzinfo(self) -> _TzInfo | None: ...
@property
def fold(self) -> int: ...
# The first parameter in `fromtimestamp` is actually positional-or-keyword,
# but it is named "timestamp" in the C implementation and "t" in the Python implementation,
# so it is only truly *safe* to pass it as a positional argument.
@classmethod
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
# On <3.12, the name of the first parameter in the pure-Python implementation
# didn't match the name in the C implementation,
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
if sys.version_info >= (3, 12):
@classmethod
def fromtimestamp(cls: type[Self], timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
else:
@classmethod
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ...

@classmethod
def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ...
if sys.version_info >= (3, 8):
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/json/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import SupportsRead
from _typeshed import SupportsRead, SupportsWrite
from collections.abc import Callable
from typing import IO, Any
from typing import Any

from .decoder import JSONDecodeError as JSONDecodeError, JSONDecoder as JSONDecoder
from .encoder import JSONEncoder as JSONEncoder
Expand All @@ -23,7 +23,7 @@ def dumps(
) -> str: ...
def dump(
obj: Any,
fp: IO[str],
fp: SupportsWrite[str],
*,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/json/encoder.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JSONEncoder:
check_circular: bool
allow_nan: bool
sort_keys: bool
indent: int
indent: int | str
def __init__(
self,
*,
Expand All @@ -29,7 +29,7 @@ class JSONEncoder:
check_circular: bool = ...,
allow_nan: bool = ...,
sort_keys: bool = ...,
indent: int | None = ...,
indent: int | str | None = ...,
separators: tuple[str, str] | None = ...,
default: Callable[..., Any] | None = ...,
) -> None: ...
Expand Down
6 changes: 5 additions & 1 deletion mypy/typeshed/stdlib/netrc.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from _typeshed import StrOrBytesPath
from typing_extensions import TypeAlias

Expand All @@ -10,7 +11,10 @@ class NetrcParseError(Exception):
def __init__(self, msg: str, filename: StrOrBytesPath | None = ..., lineno: int | None = ...) -> None: ...

# (login, account, password) tuple
_NetrcTuple: TypeAlias = tuple[str, str | None, str | None]
if sys.version_info >= (3, 11):
_NetrcTuple: TypeAlias = tuple[str, str, str]
else:
_NetrcTuple: TypeAlias = tuple[str, str | None, str | None]

class netrc:
hosts: dict[str, _NetrcTuple]
Expand Down
Loading