Skip to content

Commit 2a6d9cb

Browse files
Sync typeshed (#16009)
Source commit: python/typeshed@f28cb8b
1 parent df4717e commit 2a6d9cb

19 files changed

+233
-86
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _CData(metaclass=_CDataMeta):
6969
def __buffer__(self, __flags: int) -> memoryview: ...
7070
def __release_buffer__(self, __buffer: memoryview) -> None: ...
7171

72-
class _SimpleCData(Generic[_T], _CData):
72+
class _SimpleCData(_CData, Generic[_T]):
7373
value: _T
7474
# The TypeVar can be unsolved here,
7575
# but we can't use overloads without creating many, many mypy false-positive errors
@@ -78,7 +78,7 @@ class _SimpleCData(Generic[_T], _CData):
7878
class _CanCastTo(_CData): ...
7979
class _PointerLike(_CanCastTo): ...
8080

81-
class _Pointer(Generic[_CT], _PointerLike, _CData):
81+
class _Pointer(_PointerLike, _CData, Generic[_CT]):
8282
_type_: type[_CT]
8383
contents: _CT
8484
@overload
@@ -140,7 +140,7 @@ class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
140140
class Union(_StructUnionBase): ...
141141
class Structure(_StructUnionBase): ...
142142

143-
class Array(Generic[_CT], _CData):
143+
class Array(_CData, Generic[_CT]):
144144
@property
145145
@abstractmethod
146146
def _length_(self) -> int: ...

mypy/typeshed/stdlib/asyncio/taskgroups.pyi

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22
from contextvars import Context
33
from types import TracebackType
4-
from typing import TypeVar
4+
from typing import Any, TypeVar
55
from typing_extensions import Self
66

77
from . import _CoroutineLike
8+
from .events import AbstractEventLoop
89
from .tasks import Task
910

1011
if sys.version_info >= (3, 12):
@@ -15,6 +16,10 @@ else:
1516
_T = TypeVar("_T")
1617

1718
class TaskGroup:
19+
_loop: AbstractEventLoop | None
20+
_tasks: set[Task[Any]]
21+
1822
async def __aenter__(self) -> Self: ...
1923
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
2024
def create_task(self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ...
25+
def _on_task_done(self, task: Task[object]) -> None: ...

mypy/typeshed/stdlib/asyncio/tasks.pyi

+21-9
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,6 @@ if sys.version_info >= (3, 10):
243243
async def sleep(delay: float) -> None: ...
244244
@overload
245245
async def sleep(delay: float, result: _T) -> _T: ...
246-
@overload
247-
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
248-
@overload
249-
async def wait(
250-
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
251-
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
252246
async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ...
253247

254248
else:
@@ -257,6 +251,25 @@ else:
257251
async def sleep(delay: float, *, loop: AbstractEventLoop | None = None) -> None: ...
258252
@overload
259253
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = None) -> _T: ...
254+
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...
255+
256+
if sys.version_info >= (3, 11):
257+
@overload
258+
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
259+
@overload
260+
async def wait(
261+
fs: Iterable[Task[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
262+
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
263+
264+
elif sys.version_info >= (3, 10):
265+
@overload
266+
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
267+
@overload
268+
async def wait(
269+
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
270+
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
271+
272+
else:
260273
@overload
261274
async def wait( # type: ignore[misc]
262275
fs: Iterable[_FT],
@@ -273,7 +286,6 @@ else:
273286
timeout: float | None = None,
274287
return_when: str = "ALL_COMPLETED",
275288
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
276-
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...
277289

278290
if sys.version_info >= (3, 12):
279291
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
@@ -291,7 +303,7 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
291303
coro: _TaskCompatibleCoro[_T_co],
292304
*,
293305
loop: AbstractEventLoop = ...,
294-
name: str | None,
306+
name: str | None = ...,
295307
context: Context | None = None,
296308
eager_start: bool = False,
297309
) -> None: ...
@@ -301,7 +313,7 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
301313
coro: _TaskCompatibleCoro[_T_co],
302314
*,
303315
loop: AbstractEventLoop = ...,
304-
name: str | None,
316+
name: str | None = ...,
305317
context: Context | None = None,
306318
) -> None: ...
307319
elif sys.version_info >= (3, 8):

mypy/typeshed/stdlib/configparser.pyi

+54-27
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,53 @@ from re import Pattern
55
from typing import Any, ClassVar, TypeVar, overload
66
from typing_extensions import Literal, TypeAlias
77

8-
__all__ = [
9-
"NoSectionError",
10-
"DuplicateOptionError",
11-
"DuplicateSectionError",
12-
"NoOptionError",
13-
"InterpolationError",
14-
"InterpolationDepthError",
15-
"InterpolationMissingOptionError",
16-
"InterpolationSyntaxError",
17-
"ParsingError",
18-
"MissingSectionHeaderError",
19-
"ConfigParser",
20-
"RawConfigParser",
21-
"Interpolation",
22-
"BasicInterpolation",
23-
"ExtendedInterpolation",
24-
"LegacyInterpolation",
25-
"SectionProxy",
26-
"ConverterMapping",
27-
"DEFAULTSECT",
28-
"MAX_INTERPOLATION_DEPTH",
29-
]
30-
31-
if sys.version_info < (3, 12):
32-
__all__ += ["SafeConfigParser"]
8+
if sys.version_info >= (3, 12):
9+
__all__ = (
10+
"NoSectionError",
11+
"DuplicateOptionError",
12+
"DuplicateSectionError",
13+
"NoOptionError",
14+
"InterpolationError",
15+
"InterpolationDepthError",
16+
"InterpolationMissingOptionError",
17+
"InterpolationSyntaxError",
18+
"ParsingError",
19+
"MissingSectionHeaderError",
20+
"ConfigParser",
21+
"RawConfigParser",
22+
"Interpolation",
23+
"BasicInterpolation",
24+
"ExtendedInterpolation",
25+
"LegacyInterpolation",
26+
"SectionProxy",
27+
"ConverterMapping",
28+
"DEFAULTSECT",
29+
"MAX_INTERPOLATION_DEPTH",
30+
)
31+
else:
32+
__all__ = [
33+
"NoSectionError",
34+
"DuplicateOptionError",
35+
"DuplicateSectionError",
36+
"NoOptionError",
37+
"InterpolationError",
38+
"InterpolationDepthError",
39+
"InterpolationMissingOptionError",
40+
"InterpolationSyntaxError",
41+
"ParsingError",
42+
"MissingSectionHeaderError",
43+
"ConfigParser",
44+
"SafeConfigParser",
45+
"RawConfigParser",
46+
"Interpolation",
47+
"BasicInterpolation",
48+
"ExtendedInterpolation",
49+
"LegacyInterpolation",
50+
"SectionProxy",
51+
"ConverterMapping",
52+
"DEFAULTSECT",
53+
"MAX_INTERPOLATION_DEPTH",
54+
]
3355

3456
_Section: TypeAlias = Mapping[str, str]
3557
_Parser: TypeAlias = MutableMapping[str, _Section]
@@ -128,7 +150,8 @@ class RawConfigParser(_Parser):
128150
def read_file(self, f: Iterable[str], source: str | None = None) -> None: ...
129151
def read_string(self, string: str, source: str = "<string>") -> None: ...
130152
def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = "<dict>") -> None: ...
131-
def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: ...
153+
if sys.version_info < (3, 12):
154+
def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: ...
132155
# These get* methods are partially applied (with the same names) in
133156
# SectionProxy; the stubs should be kept updated together
134157
@overload
@@ -277,7 +300,11 @@ class InterpolationSyntaxError(InterpolationError): ...
277300
class ParsingError(Error):
278301
source: str
279302
errors: list[tuple[int, str]]
280-
def __init__(self, source: str | None = None, filename: str | None = None) -> None: ...
303+
if sys.version_info >= (3, 12):
304+
def __init__(self, source: str) -> None: ...
305+
else:
306+
def __init__(self, source: str | None = None, filename: str | None = None) -> None: ...
307+
281308
def append(self, lineno: int, line: str) -> None: ...
282309

283310
class MissingSectionHeaderError(ParsingError):

mypy/typeshed/stdlib/csv.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class excel(Dialect): ...
6969
class excel_tab(excel): ...
7070
class unix_dialect(Dialect): ...
7171

72-
class DictReader(Generic[_T], Iterator[_DictReadMapping[_T | Any, str | Any]]):
72+
class DictReader(Iterator[_DictReadMapping[_T | Any, str | Any]], Generic[_T]):
7373
fieldnames: Sequence[_T] | None
7474
restkey: str | None
7575
restval: str | None

mypy/typeshed/stdlib/enum.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if sys.version_info >= (3, 11):
3333
"verify",
3434
]
3535

36-
if sys.version_info >= (3, 12):
36+
if sys.version_info >= (3, 11):
3737
__all__ += ["pickle_by_enum_name", "pickle_by_global_name"]
3838

3939
_EnumMemberT = TypeVar("_EnumMemberT")
@@ -188,7 +188,7 @@ class Enum(metaclass=EnumMeta):
188188
def __hash__(self) -> int: ...
189189
def __format__(self, format_spec: str) -> str: ...
190190
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...
191-
if sys.version_info >= (3, 12):
191+
if sys.version_info >= (3, 11):
192192
def __copy__(self) -> Self: ...
193193
def __deepcopy__(self, memo: Any) -> Self: ...
194194

@@ -294,6 +294,6 @@ class auto(IntFlag):
294294
def value(self) -> Any: ...
295295
def __new__(cls) -> Self: ...
296296

297-
if sys.version_info >= (3, 12):
297+
if sys.version_info >= (3, 11):
298298
def pickle_by_global_name(self: Enum, proto: int) -> str: ...
299299
def pickle_by_enum_name(self: _EnumMemberT, proto: int) -> tuple[Callable[..., Any], tuple[type[_EnumMemberT], str]]: ...

mypy/typeshed/stdlib/genericpath.pyi

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
2-
from _typeshed import BytesPath, FileDescriptorOrPath, StrPath, SupportsRichComparisonT
2+
import sys
3+
from _typeshed import BytesPath, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRichComparisonT
34
from collections.abc import Sequence
45
from typing import overload
56
from typing_extensions import Literal, LiteralString
@@ -17,6 +18,8 @@ __all__ = [
1718
"sameopenfile",
1819
"samestat",
1920
]
21+
if sys.version_info >= (3, 12):
22+
__all__ += ["islink"]
2023

2124
# All overloads can return empty string. Ideally, Literal[""] would be a valid
2225
# Iterable[T], so that list[T] | Literal[""] could be used as a return
@@ -36,6 +39,9 @@ def getsize(filename: FileDescriptorOrPath) -> int: ...
3639
def isfile(path: FileDescriptorOrPath) -> bool: ...
3740
def isdir(s: FileDescriptorOrPath) -> bool: ...
3841

42+
if sys.version_info >= (3, 12):
43+
def islink(path: StrOrBytesPath) -> bool: ...
44+
3945
# These return float if os.stat_float_times() == True,
4046
# but int is a subclass of float.
4147
def getatime(filename: FileDescriptorOrPath) -> float: ...

mypy/typeshed/stdlib/gzip.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ class GzipFile(_compression.BaseStream):
139139
fileobj: _ReadableFileobj | _WritableFileobj | None = None,
140140
mtime: float | None = None,
141141
) -> None: ...
142-
@property
143-
def filename(self) -> str: ...
142+
if sys.version_info < (3, 12):
143+
@property
144+
def filename(self) -> str: ...
145+
144146
@property
145147
def mtime(self) -> int | None: ...
146148
crc: int

mypy/typeshed/stdlib/ntpath.pyi

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ from posixpath import (
4242
splitext as splitext,
4343
supports_unicode_filenames as supports_unicode_filenames,
4444
)
45+
46+
if sys.version_info >= (3, 12):
47+
from posixpath import isjunction as isjunction, splitroot as splitroot
4548
from typing import AnyStr, overload
4649
from typing_extensions import LiteralString
4750

@@ -85,6 +88,8 @@ __all__ = [
8588
"samestat",
8689
"commonpath",
8790
]
91+
if sys.version_info >= (3, 12):
92+
__all__ += ["isjunction", "splitroot"]
8893

8994
altsep: LiteralString
9095

mypy/typeshed/stdlib/os/__init__.pyi

+8-1
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ class DirEntry(Generic[AnyStr]):
388388
def __fspath__(self) -> AnyStr: ...
389389
if sys.version_info >= (3, 9):
390390
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
391+
if sys.version_info >= (3, 12):
392+
def is_junction(self) -> bool: ...
391393

392394
@final
393395
class statvfs_result(structseq[int], tuple[int, int, int, int, int, int, int, int, int, int, int]):
@@ -602,7 +604,12 @@ def isatty(__fd: int) -> bool: ...
602604
if sys.platform != "win32" and sys.version_info >= (3, 11):
603605
def login_tty(__fd: int) -> None: ...
604606

605-
def lseek(__fd: int, __position: int, __how: int) -> int: ...
607+
if sys.version_info >= (3, 11):
608+
def lseek(__fd: int, __position: int, __whence: int) -> int: ...
609+
610+
else:
611+
def lseek(__fd: int, __position: int, __how: int) -> int: ...
612+
606613
def open(path: StrOrBytesPath, flags: int, mode: int = 0o777, *, dir_fd: int | None = None) -> int: ...
607614
def pipe() -> tuple[int, int]: ...
608615
def read(__fd: int, __length: int) -> bytes: ...

mypy/typeshed/stdlib/posixpath.pyi

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ __all__ = [
5858
"relpath",
5959
"commonpath",
6060
]
61+
if sys.version_info >= (3, 12):
62+
__all__ += ["isjunction", "splitroot"]
6163

6264
supports_unicode_filenames: bool
6365
# aliases (also in os)
@@ -150,3 +152,10 @@ def isabs(s: StrOrBytesPath) -> bool: ...
150152
def islink(path: FileDescriptorOrPath) -> bool: ...
151153
def ismount(path: FileDescriptorOrPath) -> bool: ...
152154
def lexists(path: FileDescriptorOrPath) -> bool: ...
155+
156+
if sys.version_info >= (3, 12):
157+
def isjunction(path: StrOrBytesPath) -> bool: ...
158+
@overload
159+
def splitroot(p: AnyOrLiteralStr) -> tuple[AnyOrLiteralStr, AnyOrLiteralStr, AnyOrLiteralStr]: ...
160+
@overload
161+
def splitroot(p: PathLike[AnyStr]) -> tuple[AnyStr, AnyStr, AnyStr]: ...

mypy/typeshed/stdlib/pydoc.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def render_doc(
198198
thing: str | object, title: str = "Python Library Documentation: %s", forceload: bool = ..., renderer: Doc | None = None
199199
) -> str: ...
200200

201-
if sys.version_info >= (3, 12):
201+
if sys.version_info >= (3, 11):
202202
def doc(
203203
thing: str | object,
204204
title: str = "Python Library Documentation: %s",
@@ -230,7 +230,7 @@ class Helper:
230230
def __call__(self, request: str | Helper | object = ...) -> None: ...
231231
def interact(self) -> None: ...
232232
def getline(self, prompt: str) -> str: ...
233-
if sys.version_info >= (3, 12):
233+
if sys.version_info >= (3, 11):
234234
def help(self, request: Any, is_cli: bool = False) -> None: ...
235235
else:
236236
def help(self, request: Any) -> None: ...

0 commit comments

Comments
 (0)