Skip to content

Commit c831654

Browse files
Sync typeshed (#14375)
Source commit: python/typeshed@46f0d91 Co-authored-by: mypybot <> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent 9183b28 commit c831654

File tree

17 files changed

+275
-140
lines changed

17 files changed

+275
-140
lines changed

mypy/typeshed/stdlib/_winapi.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ if sys.platform == "win32":
184184
def PeekNamedPipe(__handle: int, __size: int = ...) -> tuple[int, int] | tuple[bytes, int, int]: ...
185185
if sys.version_info >= (3, 10):
186186
def LCMapStringEx(locale: str, flags: int, src: str) -> str: ...
187+
def UnmapViewOfFile(__address: int) -> None: ...
187188

188189
@overload
189190
def ReadFile(handle: int, size: int, overlapped: Literal[True]) -> tuple[Overlapped, int]: ...

mypy/typeshed/stdlib/ast.pyi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class NodeVisitor:
8989
def visit_Constant(self, node: Constant) -> Any: ...
9090
if sys.version_info >= (3, 8):
9191
def visit_NamedExpr(self, node: NamedExpr) -> Any: ...
92+
def visit_TypeIgnore(self, node: TypeIgnore) -> Any: ...
9293

9394
def visit_Attribute(self, node: Attribute) -> Any: ...
9495
def visit_Subscript(self, node: Subscript) -> Any: ...
@@ -135,6 +136,19 @@ class NodeVisitor:
135136
def visit_keyword(self, node: keyword) -> Any: ...
136137
def visit_alias(self, node: alias) -> Any: ...
137138
def visit_withitem(self, node: withitem) -> Any: ...
139+
if sys.version_info >= (3, 10):
140+
def visit_Match(self, node: Match) -> Any: ...
141+
def visit_MatchValue(self, node: MatchValue) -> Any: ...
142+
def visit_MatchSequence(self, node: MatchSequence) -> Any: ...
143+
def visit_MatchStar(self, node: MatchStar) -> Any: ...
144+
def visit_MatchMapping(self, node: MatchMapping) -> Any: ...
145+
def visit_MatchClass(self, node: MatchClass) -> Any: ...
146+
def visit_MatchAs(self, node: MatchAs) -> Any: ...
147+
def visit_MatchOr(self, node: MatchOr) -> Any: ...
148+
149+
if sys.version_info >= (3, 11):
150+
def visit_TryStar(self, node: TryStar) -> Any: ...
151+
138152
# visit methods for deprecated nodes
139153
def visit_ExtSlice(self, node: ExtSlice) -> Any: ...
140154
def visit_Index(self, node: Index) -> Any: ...
@@ -261,7 +275,7 @@ else:
261275
def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ...
262276

263277
def fix_missing_locations(node: _T) -> _T: ...
264-
def get_docstring(node: AST, clean: bool = ...) -> str | None: ...
278+
def get_docstring(node: AsyncFunctionDef | FunctionDef | ClassDef | Module, clean: bool = ...) -> str | None: ...
265279
def increment_lineno(node: _T, n: int = ...) -> _T: ...
266280
def iter_child_nodes(node: AST) -> Iterator[AST]: ...
267281
def iter_fields(node: AST) -> Iterator[tuple[str, Any]]: ...

mypy/typeshed/stdlib/asyncio/subprocess.pyi

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import subprocess
22
import sys
33
from _typeshed import StrOrBytesPath
44
from asyncio import events, protocols, streams, transports
5-
from collections.abc import Callable
5+
from collections.abc import Callable, Collection
66
from typing import IO, Any
77
from typing_extensions import Literal, TypeAlias
88

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

43-
if sys.version_info >= (3, 10):
43+
if sys.version_info >= (3, 11):
4444
async def create_subprocess_shell(
4545
cmd: str | bytes,
4646
stdin: int | IO[Any] | None = ...,
@@ -65,7 +65,13 @@ if sys.version_info >= (3, 10):
6565
creationflags: int = ...,
6666
restore_signals: bool = ...,
6767
start_new_session: bool = ...,
68-
pass_fds: Any = ...,
68+
pass_fds: Collection[int] = ...,
69+
group: None | str | int = ...,
70+
extra_groups: None | Collection[str | int] = ...,
71+
user: None | str | int = ...,
72+
umask: int = ...,
73+
process_group: int | None = ...,
74+
pipesize: int = ...,
6975
) -> Process: ...
7076
async def create_subprocess_exec(
7177
program: _ExecArg,
@@ -91,10 +97,80 @@ if sys.version_info >= (3, 10):
9197
creationflags: int = ...,
9298
restore_signals: bool = ...,
9399
start_new_session: bool = ...,
94-
pass_fds: Any = ...,
100+
pass_fds: Collection[int] = ...,
101+
group: None | str | int = ...,
102+
extra_groups: None | Collection[str | int] = ...,
103+
user: None | str | int = ...,
104+
umask: int = ...,
105+
process_group: int | None = ...,
106+
pipesize: int = ...,
95107
) -> Process: ...
96108

97-
else:
109+
elif sys.version_info >= (3, 10):
110+
async def create_subprocess_shell(
111+
cmd: str | bytes,
112+
stdin: int | IO[Any] | None = ...,
113+
stdout: int | IO[Any] | None = ...,
114+
stderr: int | IO[Any] | None = ...,
115+
limit: int = ...,
116+
*,
117+
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
118+
universal_newlines: Literal[False] = ...,
119+
shell: Literal[True] = ...,
120+
bufsize: Literal[0] = ...,
121+
encoding: None = ...,
122+
errors: None = ...,
123+
text: Literal[False, None] = ...,
124+
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
125+
executable: StrOrBytesPath | None = ...,
126+
preexec_fn: Callable[[], Any] | None = ...,
127+
close_fds: bool = ...,
128+
cwd: StrOrBytesPath | None = ...,
129+
env: subprocess._ENV | None = ...,
130+
startupinfo: Any | None = ...,
131+
creationflags: int = ...,
132+
restore_signals: bool = ...,
133+
start_new_session: bool = ...,
134+
pass_fds: Collection[int] = ...,
135+
group: None | str | int = ...,
136+
extra_groups: None | Collection[str | int] = ...,
137+
user: None | str | int = ...,
138+
umask: int = ...,
139+
pipesize: int = ...,
140+
) -> Process: ...
141+
async def create_subprocess_exec(
142+
program: _ExecArg,
143+
*args: _ExecArg,
144+
stdin: int | IO[Any] | None = ...,
145+
stdout: int | IO[Any] | None = ...,
146+
stderr: int | IO[Any] | None = ...,
147+
limit: int = ...,
148+
# These parameters are forced to these values by BaseEventLoop.subprocess_shell
149+
universal_newlines: Literal[False] = ...,
150+
shell: Literal[True] = ...,
151+
bufsize: Literal[0] = ...,
152+
encoding: None = ...,
153+
errors: None = ...,
154+
# These parameters are taken by subprocess.Popen, which this ultimately delegates to
155+
text: bool | None = ...,
156+
executable: StrOrBytesPath | None = ...,
157+
preexec_fn: Callable[[], Any] | None = ...,
158+
close_fds: bool = ...,
159+
cwd: StrOrBytesPath | None = ...,
160+
env: subprocess._ENV | None = ...,
161+
startupinfo: Any | None = ...,
162+
creationflags: int = ...,
163+
restore_signals: bool = ...,
164+
start_new_session: bool = ...,
165+
pass_fds: Collection[int] = ...,
166+
group: None | str | int = ...,
167+
extra_groups: None | Collection[str | int] = ...,
168+
user: None | str | int = ...,
169+
umask: int = ...,
170+
pipesize: int = ...,
171+
) -> Process: ...
172+
173+
else: # >= 3.9
98174
async def create_subprocess_shell(
99175
cmd: str | bytes,
100176
stdin: int | IO[Any] | None = ...,
@@ -120,7 +196,11 @@ else:
120196
creationflags: int = ...,
121197
restore_signals: bool = ...,
122198
start_new_session: bool = ...,
123-
pass_fds: Any = ...,
199+
pass_fds: Collection[int] = ...,
200+
group: None | str | int = ...,
201+
extra_groups: None | Collection[str | int] = ...,
202+
user: None | str | int = ...,
203+
umask: int = ...,
124204
) -> Process: ...
125205
async def create_subprocess_exec(
126206
program: _ExecArg,
@@ -147,5 +227,9 @@ else:
147227
creationflags: int = ...,
148228
restore_signals: bool = ...,
149229
start_new_session: bool = ...,
150-
pass_fds: Any = ...,
230+
pass_fds: Collection[int] = ...,
231+
group: None | str | int = ...,
232+
extra_groups: None | Collection[str | int] = ...,
233+
user: None | str | int = ...,
234+
umask: int = ...,
151235
) -> Process: ...

mypy/typeshed/stdlib/asyncio/tasks.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ else:
270270
# While this is true in general, here it's sort-of okay to have a covariant subclass,
271271
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
272272
# and `asyncio.Task.set_result()` always raises.
273-
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var]
273+
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
274274
if sys.version_info >= (3, 8):
275275
def __init__(
276276
self,

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import _ast
12
import sys
23
import types
3-
from _ast import AST
44
from _collections_abc import dict_items, dict_keys, dict_values
55
from _typeshed import (
66
AnyStr_co,
@@ -1096,7 +1096,7 @@ class property:
10961096
class _NotImplementedType(Any): # type: ignore[misc]
10971097
# A little weird, but typing the __call__ as NotImplemented makes the error message
10981098
# for NotImplemented() much better
1099-
__call__: NotImplemented # type: ignore[valid-type]
1099+
__call__: NotImplemented # type: ignore[valid-type] # pyright: ignore[reportGeneralTypeIssues]
11001100

11011101
NotImplemented: _NotImplementedType
11021102

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

11441144
else:
11451145
def compile(
1146-
source: str | ReadableBuffer | AST,
1146+
source: str | ReadableBuffer | _ast.Module | _ast.Expression | _ast.Interactive,
11471147
filename: str | ReadableBuffer | _PathLike[Any],
11481148
mode: str,
11491149
flags: int = ...,

mypy/typeshed/stdlib/collections/__init__.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,17 @@ class _OrderedDictValuesView(ValuesView[_VT_co], Reversible[_VT_co]):
327327
# The C implementations of the "views" classes
328328
# (At runtime, these are called `odict_keys`, `odict_items` and `odict_values`,
329329
# but they are not exposed anywhere)
330+
# pyright doesn't have a specific error code for subclassing error!
330331
@final
331-
class _odict_keys(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc]
332+
class _odict_keys(dict_keys[_KT_co, _VT_co], Reversible[_KT_co]): # type: ignore[misc] # pyright: ignore
332333
def __reversed__(self) -> Iterator[_KT_co]: ...
333334

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

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

342343
class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):

mypy/typeshed/stdlib/ctypes/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class _CDataMeta(type):
6464
# By default mypy complains about the following two methods, because strictly speaking cls
6565
# might not be a Type[_CT]. However this can never actually happen, because the only class that
6666
# uses _CDataMeta as its metaclass is _CData. So it's safe to ignore the errors here.
67-
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc]
68-
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc]
67+
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
68+
def __rmul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
6969

7070
class _CData(metaclass=_CDataMeta):
7171
_b_base: int

mypy/typeshed/stdlib/datetime.pyi

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ class date:
7070
@property
7171
def day(self) -> int: ...
7272
def ctime(self) -> str: ...
73-
def strftime(self, __format: str) -> str: ...
73+
# On <3.12, the name of the parameter in the pure-Python implementation
74+
# didn't match the name in the C implementation,
75+
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
76+
if sys.version_info >= (3, 12):
77+
def strftime(self, format: str) -> str: ...
78+
else:
79+
def strftime(self, __format: str) -> str: ...
80+
7481
def __format__(self, __fmt: str) -> str: ...
7582
def isoformat(self) -> str: ...
7683
def timetuple(self) -> struct_time: ...
@@ -140,7 +147,14 @@ class time:
140147
def isoformat(self, timespec: str = ...) -> str: ...
141148
@classmethod
142149
def fromisoformat(cls: type[Self], __time_string: str) -> Self: ...
143-
def strftime(self, __format: str) -> str: ...
150+
# On <3.12, the name of the parameter in the pure-Python implementation
151+
# didn't match the name in the C implementation,
152+
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
153+
if sys.version_info >= (3, 12):
154+
def strftime(self, format: str) -> str: ...
155+
else:
156+
def strftime(self, __format: str) -> str: ...
157+
144158
def __format__(self, __fmt: str) -> str: ...
145159
def utcoffset(self) -> timedelta | None: ...
146160
def tzname(self) -> str | None: ...
@@ -233,11 +247,16 @@ class datetime(date):
233247
def tzinfo(self) -> _TzInfo | None: ...
234248
@property
235249
def fold(self) -> int: ...
236-
# The first parameter in `fromtimestamp` is actually positional-or-keyword,
237-
# but it is named "timestamp" in the C implementation and "t" in the Python implementation,
238-
# so it is only truly *safe* to pass it as a positional argument.
239-
@classmethod
240-
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
250+
# On <3.12, the name of the first parameter in the pure-Python implementation
251+
# didn't match the name in the C implementation,
252+
# meaning it is only *safe* to pass it as a keyword argument on 3.12+
253+
if sys.version_info >= (3, 12):
254+
@classmethod
255+
def fromtimestamp(cls: type[Self], timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
256+
else:
257+
@classmethod
258+
def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ...
259+
241260
@classmethod
242261
def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ...
243262
if sys.version_info >= (3, 8):

mypy/typeshed/stdlib/json/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from _typeshed import SupportsRead
1+
from _typeshed import SupportsRead, SupportsWrite
22
from collections.abc import Callable
3-
from typing import IO, Any
3+
from typing import Any
44

55
from .decoder import JSONDecodeError as JSONDecodeError, JSONDecoder as JSONDecoder
66
from .encoder import JSONEncoder as JSONEncoder
@@ -23,7 +23,7 @@ def dumps(
2323
) -> str: ...
2424
def dump(
2525
obj: Any,
26-
fp: IO[str],
26+
fp: SupportsWrite[str],
2727
*,
2828
skipkeys: bool = ...,
2929
ensure_ascii: bool = ...,

mypy/typeshed/stdlib/json/encoder.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class JSONEncoder:
2020
check_circular: bool
2121
allow_nan: bool
2222
sort_keys: bool
23-
indent: int
23+
indent: int | str
2424
def __init__(
2525
self,
2626
*,
@@ -29,7 +29,7 @@ class JSONEncoder:
2929
check_circular: bool = ...,
3030
allow_nan: bool = ...,
3131
sort_keys: bool = ...,
32-
indent: int | None = ...,
32+
indent: int | str | None = ...,
3333
separators: tuple[str, str] | None = ...,
3434
default: Callable[..., Any] | None = ...,
3535
) -> None: ...

0 commit comments

Comments
 (0)