Skip to content

Commit 7237d55

Browse files
authored
Sync typeshed (#17833)
Source commit: python/typeshed@a94c927
1 parent db7b61b commit 7237d55

File tree

9 files changed

+254
-41
lines changed

9 files changed

+254
-41
lines changed

mypy/typeshed/stdlib/VERSIONS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ importlib.metadata._meta: 3.10-
161161
importlib.metadata.diagnose: 3.13-
162162
importlib.readers: 3.10-
163163
importlib.resources: 3.7-
164+
importlib.resources._common: 3.11-
165+
importlib.resources._functional: 3.13-
164166
importlib.resources.abc: 3.11-
165167
importlib.resources.readers: 3.11-
166168
importlib.resources.simple: 3.11-

mypy/typeshed/stdlib/importlib/abc.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ if sys.version_info >= (3, 9):
145145
# which is not the case.
146146
@overload
147147
@abstractmethod
148-
def open(self, mode: Literal["r"] = "r", /, *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
148+
def open(self, mode: Literal["r"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
149149
@overload
150150
@abstractmethod
151-
def open(self, mode: Literal["rb"], /) -> IO[bytes]: ...
151+
def open(self, mode: Literal["rb"]) -> IO[bytes]: ...
152152
@property
153153
@abstractmethod
154154
def name(self) -> str: ...

mypy/typeshed/stdlib/importlib/resources/__init__.pyi

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,61 @@ from types import ModuleType
77
from typing import Any, BinaryIO, TextIO
88
from typing_extensions import TypeAlias
99

10+
if sys.version_info >= (3, 11):
11+
from importlib.resources._common import Package as Package
12+
else:
13+
Package: TypeAlias = str | ModuleType
14+
1015
if sys.version_info >= (3, 9):
1116
from importlib.abc import Traversable
1217

13-
__all__ = ["Package", "Resource", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"]
18+
__all__ = ["Package", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"]
1419

1520
if sys.version_info >= (3, 9):
1621
__all__ += ["as_file", "files"]
1722

1823
if sys.version_info >= (3, 10):
1924
__all__ += ["ResourceReader"]
2025

21-
Package: TypeAlias = str | ModuleType
26+
if sys.version_info < (3, 13):
27+
__all__ += ["Resource"]
2228

23-
if sys.version_info >= (3, 11):
24-
Resource: TypeAlias = str
25-
else:
29+
if sys.version_info < (3, 11):
2630
Resource: TypeAlias = str | os.PathLike[Any]
31+
elif sys.version_info < (3, 13):
32+
Resource: TypeAlias = str
2733

28-
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
29-
def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ...
30-
def read_binary(package: Package, resource: Resource) -> bytes: ...
31-
def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ...
32-
def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ...
33-
def is_resource(package: Package, name: str) -> bool: ...
34-
def contents(package: Package) -> Iterator[str]: ...
34+
if sys.version_info >= (3, 13):
35+
from importlib.resources._common import Anchor as Anchor
3536

36-
if sys.version_info >= (3, 9):
37+
__all__ += ["Anchor"]
38+
39+
from importlib.resources._functional import (
40+
contents as contents,
41+
is_resource as is_resource,
42+
open_binary as open_binary,
43+
open_text as open_text,
44+
path as path,
45+
read_binary as read_binary,
46+
read_text as read_text,
47+
)
48+
49+
else:
50+
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
51+
def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ...
52+
def read_binary(package: Package, resource: Resource) -> bytes: ...
53+
def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ...
54+
def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ...
55+
def is_resource(package: Package, name: str) -> bool: ...
56+
def contents(package: Package) -> Iterator[str]: ...
57+
58+
if sys.version_info >= (3, 11):
59+
from importlib.resources._common import as_file as as_file
60+
elif sys.version_info >= (3, 9):
3761
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
3862

39-
if sys.version_info >= (3, 12):
40-
def files(anchor: Package | None = ...) -> Traversable: ...
63+
if sys.version_info >= (3, 11):
64+
from importlib.resources._common import files as files
4165

4266
elif sys.version_info >= (3, 9):
4367
def files(package: Package) -> Traversable: ...
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
3+
# Even though this file is 3.11+ only, Pyright will complain in stubtest for older versions.
4+
if sys.version_info >= (3, 11):
5+
import types
6+
from collections.abc import Callable
7+
from contextlib import AbstractContextManager
8+
from importlib.abc import ResourceReader, Traversable
9+
from pathlib import Path
10+
from typing import overload
11+
from typing_extensions import TypeAlias, deprecated
12+
13+
Package: TypeAlias = str | types.ModuleType
14+
15+
if sys.version_info >= (3, 12):
16+
Anchor: TypeAlias = Package
17+
18+
def package_to_anchor(
19+
func: Callable[[Anchor | None], Traversable]
20+
) -> Callable[[Anchor | None, Anchor | None], Traversable]: ...
21+
@overload
22+
def files(anchor: Anchor | None = None) -> Traversable: ...
23+
@overload
24+
@deprecated("First parameter to files is renamed to 'anchor'")
25+
def files(package: Anchor | None = None) -> Traversable: ...
26+
27+
else:
28+
def files(package: Package) -> Traversable: ...
29+
30+
def get_resource_reader(package: types.ModuleType) -> ResourceReader | None: ...
31+
32+
if sys.version_info >= (3, 12):
33+
def resolve(cand: Anchor | None) -> types.ModuleType: ...
34+
35+
else:
36+
def resolve(cand: Package) -> types.ModuleType: ...
37+
38+
if sys.version_info < (3, 12):
39+
def get_package(package: Package) -> types.ModuleType: ...
40+
41+
def from_package(package: types.ModuleType) -> Traversable: ...
42+
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
3+
# Even though this file is 3.13+ only, Pyright will complain in stubtest for older versions.
4+
if sys.version_info >= (3, 13):
5+
from _typeshed import StrPath
6+
from collections.abc import Iterator
7+
from contextlib import AbstractContextManager
8+
from importlib.resources._common import Anchor
9+
from io import TextIOWrapper
10+
from pathlib import Path
11+
from typing import BinaryIO, overload
12+
from typing_extensions import Unpack
13+
14+
def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ...
15+
@overload
16+
def open_text(
17+
anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict"
18+
) -> TextIOWrapper: ...
19+
@overload
20+
def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ...
21+
def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ...
22+
@overload
23+
def read_text(
24+
anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict"
25+
) -> str: ...
26+
@overload
27+
def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ...
28+
def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ...
29+
def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ...
30+
def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ...

mypy/typeshed/stdlib/nt.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,7 @@ if sys.platform == "win32":
107107
listvolumes as listvolumes,
108108
set_blocking as set_blocking,
109109
)
110+
if sys.version_info >= (3, 13):
111+
from os import fchmod as fchmod, lchmod as lchmod
110112

111113
environ: dict[str, str]

mypy/typeshed/stdlib/os/__init__.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ if sys.version_info >= (3, 12) or sys.platform != "win32":
673673
def set_blocking(fd: int, blocking: bool, /) -> None: ...
674674

675675
if sys.platform != "win32":
676-
def fchmod(fd: int, mode: int) -> None: ...
677676
def fchown(fd: int, uid: int, gid: int) -> None: ...
678677
def fpathconf(fd: int, name: str | int, /) -> int: ...
679678
def fstatvfs(fd: int, /) -> statvfs_result: ...
@@ -754,7 +753,6 @@ def chmod(path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = None, f
754753
if sys.platform != "win32" and sys.platform != "linux":
755754
def chflags(path: StrOrBytesPath, flags: int, follow_symlinks: bool = True) -> None: ... # some flavors of Unix
756755
def lchflags(path: StrOrBytesPath, flags: int) -> None: ...
757-
def lchmod(path: StrOrBytesPath, mode: int) -> None: ...
758756

759757
if sys.platform != "win32":
760758
def chroot(path: StrOrBytesPath) -> None: ...
@@ -1179,3 +1177,12 @@ if sys.version_info >= (3, 13) and sys.platform == "linux":
11791177
def timerfd_settime_ns(fd: FileDescriptor, /, *, flags: int = 0, initial: int = 0, interval: int = 0) -> tuple[int, int]: ...
11801178
def timerfd_gettime(fd: FileDescriptor, /) -> tuple[float, float]: ...
11811179
def timerfd_gettime_ns(fd: FileDescriptor, /) -> tuple[int, int]: ...
1180+
1181+
if sys.version_info >= (3, 13) or sys.platform != "win32":
1182+
# Added to Windows in 3.13.
1183+
def fchmod(fd: int, mode: int) -> None: ...
1184+
1185+
if sys.platform != "linux":
1186+
if sys.version_info >= (3, 13) or sys.platform != "win32":
1187+
# Added to Windows in 3.13.
1188+
def lchmod(path: StrOrBytesPath, mode: int) -> None: ...

mypy/typeshed/stdlib/tkinter/__init__.pyi

Lines changed: 127 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,27 +3025,133 @@ class Text(Widget, XView, YView):
30253025
config = configure
30263026
def bbox(self, index: _TextIndex) -> tuple[int, int, int, int] | None: ... # type: ignore[override]
30273027
def compare(self, index1: _TextIndex, op: Literal["<", "<=", "==", ">=", ">", "!="], index2: _TextIndex) -> bool: ...
3028-
@overload
3029-
def count(self, index1: _TextIndex, index2: _TextIndex) -> tuple[int] | None: ...
3030-
@overload
3031-
def count(self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /) -> tuple[int] | None: ...
3032-
@overload
3033-
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: Literal["update"], arg2: _WhatToCount, /) -> int | None: ...
3034-
@overload
3035-
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: Literal["update"], /) -> int | None: ...
3036-
@overload
3037-
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /) -> tuple[int, int]: ...
3038-
@overload
3039-
def count(
3040-
self,
3041-
index1: _TextIndex,
3042-
index2: _TextIndex,
3043-
arg1: _WhatToCount | Literal["update"],
3044-
arg2: _WhatToCount | Literal["update"],
3045-
arg3: _WhatToCount | Literal["update"],
3046-
/,
3047-
*args: _WhatToCount | Literal["update"],
3048-
) -> tuple[int, ...]: ...
3028+
if sys.version_info >= (3, 13):
3029+
@overload
3030+
def count(self, index1: _TextIndex, index2: _TextIndex, *, return_ints: Literal[True]) -> int: ...
3031+
@overload
3032+
def count(
3033+
self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /, *, return_ints: Literal[True]
3034+
) -> int: ...
3035+
@overload
3036+
def count(
3037+
self,
3038+
index1: _TextIndex,
3039+
index2: _TextIndex,
3040+
arg1: Literal["update"],
3041+
arg2: _WhatToCount,
3042+
/,
3043+
*,
3044+
return_ints: Literal[True],
3045+
) -> int: ...
3046+
@overload
3047+
def count(
3048+
self,
3049+
index1: _TextIndex,
3050+
index2: _TextIndex,
3051+
arg1: _WhatToCount,
3052+
arg2: Literal["update"],
3053+
/,
3054+
*,
3055+
return_ints: Literal[True],
3056+
) -> int: ...
3057+
@overload
3058+
def count(
3059+
self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /, *, return_ints: Literal[True]
3060+
) -> tuple[int, int]: ...
3061+
@overload
3062+
def count(
3063+
self,
3064+
index1: _TextIndex,
3065+
index2: _TextIndex,
3066+
arg1: _WhatToCount | Literal["update"],
3067+
arg2: _WhatToCount | Literal["update"],
3068+
arg3: _WhatToCount | Literal["update"],
3069+
/,
3070+
*args: _WhatToCount | Literal["update"],
3071+
return_ints: Literal[True],
3072+
) -> tuple[int, ...]: ...
3073+
@overload
3074+
def count(self, index1: _TextIndex, index2: _TextIndex, *, return_ints: Literal[False] = False) -> tuple[int] | None: ...
3075+
@overload
3076+
def count(
3077+
self,
3078+
index1: _TextIndex,
3079+
index2: _TextIndex,
3080+
arg: _WhatToCount | Literal["update"],
3081+
/,
3082+
*,
3083+
return_ints: Literal[False] = False,
3084+
) -> tuple[int] | None: ...
3085+
@overload
3086+
def count(
3087+
self,
3088+
index1: _TextIndex,
3089+
index2: _TextIndex,
3090+
arg1: Literal["update"],
3091+
arg2: _WhatToCount,
3092+
/,
3093+
*,
3094+
return_ints: Literal[False] = False,
3095+
) -> int | None: ...
3096+
@overload
3097+
def count(
3098+
self,
3099+
index1: _TextIndex,
3100+
index2: _TextIndex,
3101+
arg1: _WhatToCount,
3102+
arg2: Literal["update"],
3103+
/,
3104+
*,
3105+
return_ints: Literal[False] = False,
3106+
) -> int | None: ...
3107+
@overload
3108+
def count(
3109+
self,
3110+
index1: _TextIndex,
3111+
index2: _TextIndex,
3112+
arg1: _WhatToCount,
3113+
arg2: _WhatToCount,
3114+
/,
3115+
*,
3116+
return_ints: Literal[False] = False,
3117+
) -> tuple[int, int]: ...
3118+
@overload
3119+
def count(
3120+
self,
3121+
index1: _TextIndex,
3122+
index2: _TextIndex,
3123+
arg1: _WhatToCount | Literal["update"],
3124+
arg2: _WhatToCount | Literal["update"],
3125+
arg3: _WhatToCount | Literal["update"],
3126+
/,
3127+
*args: _WhatToCount | Literal["update"],
3128+
return_ints: Literal[False] = False,
3129+
) -> tuple[int, ...]: ...
3130+
else:
3131+
@overload
3132+
def count(self, index1: _TextIndex, index2: _TextIndex) -> tuple[int] | None: ...
3133+
@overload
3134+
def count(
3135+
self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /
3136+
) -> tuple[int] | None: ...
3137+
@overload
3138+
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: Literal["update"], arg2: _WhatToCount, /) -> int | None: ...
3139+
@overload
3140+
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: Literal["update"], /) -> int | None: ...
3141+
@overload
3142+
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /) -> tuple[int, int]: ...
3143+
@overload
3144+
def count(
3145+
self,
3146+
index1: _TextIndex,
3147+
index2: _TextIndex,
3148+
arg1: _WhatToCount | Literal["update"],
3149+
arg2: _WhatToCount | Literal["update"],
3150+
arg3: _WhatToCount | Literal["update"],
3151+
/,
3152+
*args: _WhatToCount | Literal["update"],
3153+
) -> tuple[int, ...]: ...
3154+
30493155
@overload
30503156
def debug(self, boolean: None = None) -> bool: ...
30513157
@overload

mypy/typeshed/stdlib/typing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]):
540540
def __aiter__(self) -> AsyncIterator[_T_co]: ...
541541

542542
class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra]):
543-
def __anext__(self) -> Awaitable[_YieldT_co]: ...
543+
def __anext__(self) -> Coroutine[Any, Any, _YieldT_co]: ...
544544
@abstractmethod
545545
def asend(self, value: _SendT_contra, /) -> Coroutine[Any, Any, _YieldT_co]: ...
546546
@overload

0 commit comments

Comments
 (0)