Skip to content

Commit 30260ca

Browse files
Sync typeshed (#20505)
Source commit: python/typeshed@9175667
1 parent 9262e1d commit 30260ca

File tree

14 files changed

+256
-112
lines changed

14 files changed

+256
-112
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _typeshed
2+
import builtins
23
import sys
34
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
45
from abc import abstractmethod
@@ -195,24 +196,45 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
195196
_GetT = TypeVar("_GetT")
196197
_SetT = TypeVar("_SetT")
197198

198-
# This class is not exposed. It calls itself _ctypes.CField.
199-
@final
200-
@type_check_only
201-
class _CField(Generic[_CT, _GetT, _SetT]):
202-
offset: int
203-
size: int
204-
if sys.version_info >= (3, 10):
205-
@overload
206-
def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ...
207-
@overload
208-
def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ...
209-
else:
199+
if sys.version_info >= (3, 14):
200+
@final
201+
class CField(Generic[_CT, _GetT, _SetT]):
202+
offset: int
203+
size: int
204+
name: str
205+
type: builtins.type[_CT]
206+
byte_offset: int
207+
byte_size: int
208+
is_bitfield: bool
209+
bit_offset: int
210+
bit_size: int
211+
is_anonymous: bool
210212
@overload
211-
def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ...
213+
def __get__(self, instance: None, owner: builtins.type[Any] | None = None, /) -> Self: ...
212214
@overload
213-
def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ...
215+
def __get__(self, instance: Any, owner: builtins.type[Any] | None = None, /) -> _GetT: ...
216+
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
217+
218+
_CField = CField
214219

215-
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
220+
else:
221+
@final
222+
@type_check_only
223+
class _CField(Generic[_CT, _GetT, _SetT]):
224+
offset: int
225+
size: int
226+
if sys.version_info >= (3, 10):
227+
@overload
228+
def __get__(self, instance: None, owner: type[Any] | None = None, /) -> Self: ...
229+
@overload
230+
def __get__(self, instance: Any, owner: type[Any] | None = None, /) -> _GetT: ...
231+
else:
232+
@overload
233+
def __get__(self, instance: None, owner: type[Any] | None, /) -> Self: ...
234+
@overload
235+
def __get__(self, instance: Any, owner: type[Any] | None, /) -> _GetT: ...
236+
237+
def __set__(self, instance: Any, value: _SetT, /) -> None: ...
216238

217239
# This class is not exposed. It calls itself _ctypes.UnionType.
218240
@type_check_only

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,40 @@ class _ActionsContainer:
9393
version: str = ...,
9494
**kwargs: Any,
9595
) -> Action: ...
96-
def add_argument_group(
97-
self,
98-
title: str | None = None,
99-
description: str | None = None,
100-
*,
101-
prefix_chars: str = ...,
102-
argument_default: Any = ...,
103-
conflict_handler: str = ...,
104-
) -> _ArgumentGroup: ...
96+
if sys.version_info >= (3, 14):
97+
@overload
98+
def add_argument_group(
99+
self,
100+
title: str | None = None,
101+
description: str | None = None,
102+
*,
103+
# argument_default's type must be valid for the arguments in the group
104+
argument_default: Any = ...,
105+
conflict_handler: str = ...,
106+
) -> _ArgumentGroup: ...
107+
@overload
108+
@deprecated("The `prefix_chars` parameter deprecated since Python 3.14.")
109+
def add_argument_group(
110+
self,
111+
title: str | None = None,
112+
description: str | None = None,
113+
*,
114+
prefix_chars: str,
115+
argument_default: Any = ...,
116+
conflict_handler: str = ...,
117+
) -> _ArgumentGroup: ...
118+
else:
119+
def add_argument_group(
120+
self,
121+
title: str | None = None,
122+
description: str | None = None,
123+
*,
124+
prefix_chars: str = ...,
125+
# argument_default's type must be valid for the arguments in the group
126+
argument_default: Any = ...,
127+
conflict_handler: str = ...,
128+
) -> _ArgumentGroup: ...
129+
105130
def add_mutually_exclusive_group(self, *, required: bool = False) -> _MutuallyExclusiveGroup: ...
106131
def _add_action(self, action: _ActionT) -> _ActionT: ...
107132
def _remove_action(self, action: Action) -> None: ...

mypy/typeshed/stdlib/asyncio/coroutines.pyi

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,31 @@ if sys.version_info < (3, 11):
1717
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `async def` instead.")
1818
def coroutine(func: _FunctionT) -> _FunctionT: ...
1919

20-
@overload
21-
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
22-
@overload
23-
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
24-
@overload
25-
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
26-
@overload
27-
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
2820
def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ...
21+
22+
if sys.version_info >= (3, 11):
23+
@overload
24+
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
25+
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
26+
@overload
27+
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
28+
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
29+
@overload
30+
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
31+
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
32+
@overload
33+
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
34+
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
35+
36+
else:
37+
# Sometimes needed in Python < 3.11 due to the fact that it supports @coroutine
38+
# which was removed in 3.11 which the inspect version doesn't support.
39+
40+
@overload
41+
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
42+
@overload
43+
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
44+
@overload
45+
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
46+
@overload
47+
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...

mypy/typeshed/stdlib/codecs.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from _typeshed import ReadableBuffer
55
from abc import abstractmethod
66
from collections.abc import Callable, Generator, Iterable
77
from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload, type_check_only
8-
from typing_extensions import Self, TypeAlias, disjoint_base
8+
from typing_extensions import Self, TypeAlias, deprecated, disjoint_base
99

1010
__all__ = [
1111
"register",
@@ -191,6 +191,7 @@ def getincrementaldecoder(encoding: _BufferedEncoding) -> _BufferedIncrementalDe
191191
def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ...
192192
def getreader(encoding: str) -> _StreamReader: ...
193193
def getwriter(encoding: str) -> _StreamWriter: ...
194+
@deprecated("Deprecated since Python 3.14. Use `open()` instead.")
194195
def open(
195196
filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = -1
196197
) -> StreamReaderWriter: ...

mypy/typeshed/stdlib/ctypes/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ if sys.version_info >= (3, 14):
5555
else:
5656
from _ctypes import POINTER as POINTER, pointer as pointer
5757

58+
if sys.version_info >= (3, 14):
59+
CField = _CField
60+
5861
DEFAULT_MODE: Final[int]
5962

6063
class ArgumentError(Exception): ...

mypy/typeshed/stdlib/enum.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ _auto_null: Any
255255
class Flag(Enum):
256256
_name_: str | None # type: ignore[assignment]
257257
_value_: int
258+
_numeric_repr_: Callable[[int], str]
258259
@_magic_enum_attr
259260
def name(self) -> str | None: ... # type: ignore[override]
260261
@_magic_enum_attr

mypy/typeshed/stdlib/imaplib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class IMAP4:
6161
def socket(self) -> _socket: ...
6262
def recent(self) -> _CommandResults: ...
6363
def response(self, code: str) -> _CommandResults: ...
64-
def append(self, mailbox: str, flags: str, date_time: str, message: ReadableBuffer) -> str: ...
64+
def append(self, mailbox: str, flags: str, date_time: str, message: ReadableBuffer) -> tuple[str, _list[bytes]]: ...
6565
def authenticate(self, mechanism: str, authobject: Callable[[bytes], bytes | None]) -> tuple[str, str]: ...
6666
def capability(self) -> _CommandResults: ...
6767
def check(self) -> _CommandResults: ...

mypy/typeshed/stdlib/optparse.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class OptionContainer:
204204
callback_kwargs: dict[str, Any] | None = None,
205205
help: str | None = None,
206206
metavar: str | None = None,
207-
**kwargs, # Allow arbitrary keyword arguments for user defined option_class
207+
**kwargs: Any, # Allow arbitrary keyword arguments for user defined option_class
208208
) -> Option: ...
209209
def add_options(self, option_list: Iterable[Option]) -> None: ...
210210
def destroy(self) -> None: ...

mypy/typeshed/stdlib/os/__init__.pyi

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,18 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
710710
encodevalue: _EnvironCodeFunc[AnyStr],
711711
decodevalue: _EnvironCodeFunc[AnyStr],
712712
) -> None: ...
713+
@overload
714+
def get(self, key: AnyStr, default: None = None) -> AnyStr | None: ...
715+
@overload
716+
def get(self, key: AnyStr, default: AnyStr) -> AnyStr: ...
717+
@overload
718+
def get(self, key: AnyStr, default: _T) -> AnyStr | _T: ...
719+
@overload
720+
def pop(self, key: AnyStr) -> AnyStr: ...
721+
@overload
722+
def pop(self, key: AnyStr, default: AnyStr) -> AnyStr: ...
723+
@overload
724+
def pop(self, key: AnyStr, default: _T) -> AnyStr | _T: ...
713725
def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ...
714726
def copy(self) -> dict[AnyStr, AnyStr]: ...
715727
def __delitem__(self, key: AnyStr) -> None: ...
@@ -1395,19 +1407,48 @@ class _wrap_close:
13951407
def write(self, s: str, /) -> int: ...
13961408
def writelines(self, lines: Iterable[str], /) -> None: ...
13971409

1398-
def popen(cmd: str, mode: str = "r", buffering: int = -1) -> _wrap_close: ...
1399-
def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
1400-
def spawnle(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise sig
1410+
if sys.version_info >= (3, 14):
1411+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1412+
def popen(cmd: str, mode: str = "r", buffering: int = -1) -> _wrap_close: ...
1413+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1414+
def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
1415+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1416+
def spawnle(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise sig
1417+
1418+
else:
1419+
def popen(cmd: str, mode: str = "r", buffering: int = -1) -> _wrap_close: ...
1420+
def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
1421+
def spawnle(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise sig
14011422

14021423
if sys.platform != "win32":
1403-
def spawnv(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
1404-
def spawnve(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
1424+
if sys.version_info >= (3, 14):
1425+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1426+
def spawnv(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
1427+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1428+
def spawnve(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
1429+
1430+
else:
1431+
def spawnv(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
1432+
def spawnve(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
1433+
1434+
else:
1435+
if sys.version_info >= (3, 14):
1436+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1437+
def spawnv(mode: int, path: StrOrBytesPath, argv: _ExecVArgs, /) -> int: ...
1438+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1439+
def spawnve(mode: int, path: StrOrBytesPath, argv: _ExecVArgs, env: _ExecEnv, /) -> int: ...
1440+
1441+
else:
1442+
def spawnv(mode: int, path: StrOrBytesPath, argv: _ExecVArgs, /) -> int: ...
1443+
def spawnve(mode: int, path: StrOrBytesPath, argv: _ExecVArgs, env: _ExecEnv, /) -> int: ...
1444+
1445+
if sys.version_info >= (3, 14):
1446+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1447+
def system(command: StrOrBytesPath) -> int: ...
14051448

14061449
else:
1407-
def spawnv(mode: int, path: StrOrBytesPath, argv: _ExecVArgs, /) -> int: ...
1408-
def spawnve(mode: int, path: StrOrBytesPath, argv: _ExecVArgs, env: _ExecEnv, /) -> int: ...
1450+
def system(command: StrOrBytesPath) -> int: ...
14091451

1410-
def system(command: StrOrBytesPath) -> int: ...
14111452
@final
14121453
class times_result(structseq[float], tuple[float, float, float, float, float]):
14131454
if sys.version_info >= (3, 10):
@@ -1440,10 +1481,22 @@ if sys.platform == "win32":
14401481
def startfile(filepath: StrOrBytesPath, operation: str = ...) -> None: ...
14411482

14421483
else:
1443-
def spawnlp(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
1444-
def spawnlpe(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise signature
1445-
def spawnvp(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
1446-
def spawnvpe(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
1484+
if sys.version_info >= (3, 14):
1485+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1486+
def spawnlp(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
1487+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1488+
def spawnlpe(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise signature
1489+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1490+
def spawnvp(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
1491+
@deprecated("Soft deprecated. Use the subprocess module instead.")
1492+
def spawnvpe(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
1493+
1494+
else:
1495+
def spawnlp(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
1496+
def spawnlpe(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise signature
1497+
def spawnvp(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ...
1498+
def spawnvpe(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ...
1499+
14471500
def wait() -> tuple[int, int]: ... # Unix only
14481501
# Added to MacOS in 3.13
14491502
if sys.platform != "darwin" or sys.version_info >= (3, 13):

mypy/typeshed/stdlib/pathlib/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class PurePath(PathLike[str]):
9090
def __rtruediv__(self, key: StrPath) -> Self: ...
9191
def __bytes__(self) -> bytes: ...
9292
def as_posix(self) -> str: ...
93+
@deprecated("Deprecated since Python 3.14; will be removed in Python 3.19. Use `Path.as_uri()` instead.")
9394
def as_uri(self) -> str: ...
9495
def is_absolute(self) -> bool: ...
9596
if sys.version_info >= (3, 13):
@@ -345,6 +346,8 @@ class Path(PurePath):
345346
self, top_down: bool = True, on_error: Callable[[OSError], object] | None = None, follow_symlinks: bool = False
346347
) -> Iterator[tuple[Self, list[str], list[str]]]: ...
347348

349+
def as_uri(self) -> str: ...
350+
348351
class PosixPath(Path, PurePosixPath):
349352
__slots__ = ()
350353

0 commit comments

Comments
 (0)