Skip to content

Commit 78fea20

Browse files
committed
Sync typeshed
Source commit: python/typeshed@11c7821
1 parent 5da076b commit 78fea20

File tree

26 files changed

+493
-250
lines changed

26 files changed

+493
-250
lines changed

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from asyncio.events import AbstractEventLoop
3-
from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
3+
from collections.abc import Awaitable, Callable, Coroutine, Generator
44
from contextvars import Context
55
from types import FrameType, GenericAlias
66
from typing import Any, Literal, TextIO, TypeVar
@@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True)
1111
_TaskYieldType: TypeAlias = Future[object] | None
1212

1313
@disjoint_base
14-
class Future(Awaitable[_T], Iterable[_T]):
14+
class Future(Awaitable[_T]):
1515
_state: str
1616
@property
1717
def _exception(self) -> BaseException | None: ...

mypy/typeshed/stdlib/_csv.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ else:
9292
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
9393

9494
def writer(
95-
csvfile: SupportsWrite[str],
95+
fileobj: SupportsWrite[str],
9696
/,
9797
dialect: _DialectLike = "excel",
9898
*,
@@ -106,7 +106,7 @@ def writer(
106106
strict: bool = False,
107107
) -> _writer: ...
108108
def reader(
109-
csvfile: Iterable[str],
109+
iterable: Iterable[str],
110110
/,
111111
dialect: _DialectLike = "excel",
112112
*,
@@ -121,7 +121,8 @@ def reader(
121121
) -> _reader: ...
122122
def register_dialect(
123123
name: str,
124-
dialect: type[Dialect | csv.Dialect] = ...,
124+
/,
125+
dialect: type[Dialect | csv.Dialect] | str = "excel",
125126
*,
126127
delimiter: str = ",",
127128
quotechar: str | None = '"',

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
294294
def _type_(self) -> type[_CT]: ...
295295
@_type_.setter
296296
def _type_(self, value: type[_CT]) -> None: ...
297-
raw: bytes # Note: only available if _CT == c_char
297+
# Note: only available if _CT == c_char
298+
@property
299+
def raw(self) -> bytes: ...
300+
@raw.setter
301+
def raw(self, value: ReadableBuffer) -> None: ...
298302
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
299303
# TODO: These methods cannot be annotated correctly at the moment.
300304
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_frozen_importlib_external.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class SourceLoader(_LoaderBasics):
100100
def get_source(self, fullname: str) -> str | None: ...
101101
def path_stats(self, path: str) -> Mapping[str, Any]: ...
102102
def source_to_code(
103-
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: ReadableBuffer | StrPath
103+
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: bytes | StrPath
104104
) -> types.CodeType: ...
105105
def get_code(self, fullname: str) -> types.CodeType | None: ...
106106

@@ -109,8 +109,8 @@ class FileLoader:
109109
path: str
110110
def __init__(self, fullname: str, path: str) -> None: ...
111111
def get_data(self, path: str) -> bytes: ...
112-
def get_filename(self, name: str | None = None) -> str: ...
113-
def load_module(self, name: str | None = None) -> types.ModuleType: ...
112+
def get_filename(self, fullname: str | None = None) -> str: ...
113+
def load_module(self, fullname: str | None = None) -> types.ModuleType: ...
114114
if sys.version_info >= (3, 10):
115115
def get_resource_reader(self, name: str | None = None) -> importlib.readers.FileReader: ...
116116
else:
@@ -126,7 +126,7 @@ class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.Sourc
126126
def source_to_code( # type: ignore[override] # incompatible with InspectLoader.source_to_code
127127
self,
128128
data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive,
129-
path: ReadableBuffer | StrPath,
129+
path: bytes | StrPath,
130130
*,
131131
_optimize: int = -1,
132132
) -> types.CodeType: ...
@@ -137,7 +137,7 @@ class SourcelessFileLoader(importlib.abc.FileLoader, FileLoader, _LoaderBasics):
137137

138138
class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoader):
139139
def __init__(self, name: str, path: str) -> None: ...
140-
def get_filename(self, name: str | None = None) -> str: ...
140+
def get_filename(self, fullname: str | None = None) -> str: ...
141141
def get_source(self, fullname: str) -> None: ...
142142
def create_module(self, spec: ModuleSpec) -> types.ModuleType: ...
143143
def exec_module(self, module: types.ModuleType) -> None: ...

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class SupportsIter(Protocol[_T_co]):
142142
class SupportsAiter(Protocol[_T_co]):
143143
def __aiter__(self) -> _T_co: ...
144144

145+
class SupportsLen(Protocol):
146+
def __len__(self) -> int: ...
147+
145148
class SupportsLenAndGetItem(Protocol[_T_co]):
146149
def __len__(self) -> int: ...
147150
def __getitem__(self, k: int, /) -> _T_co: ...

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import SupportsWrite, sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload, type_check_only
5+
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload, type_check_only
66
from typing_extensions import Self, TypeAlias, deprecated
77

88
__all__ = [
@@ -36,9 +36,7 @@ ONE_OR_MORE: Final = "+"
3636
OPTIONAL: Final = "?"
3737
PARSER: Final = "A..."
3838
REMAINDER: Final = "..."
39-
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
40-
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
41-
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
39+
SUPPRESS: Final = "==SUPPRESS=="
4240
ZERO_OR_MORE: Final = "*"
4341
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
4442

@@ -81,7 +79,7 @@ class _ActionsContainer:
8179
# more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
8280
# but using this would make it hard to annotate callers that don't use a
8381
# literal argument and for subclasses to override this method.
84-
nargs: int | str | _SUPPRESS_T | None = None,
82+
nargs: int | str | None = None,
8583
const: Any = ...,
8684
default: Any = ...,
8785
type: _ActionType = ...,

mypy/typeshed/stdlib/ast.pyi

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,10 +1744,20 @@ if sys.version_info < (3, 14):
17441744
_T = _TypeVar("_T", bound=AST)
17451745

17461746
if sys.version_info >= (3, 13):
1747+
@overload
1748+
def parse(
1749+
source: _T,
1750+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
1751+
mode: Literal["exec", "eval", "func_type", "single"] = "exec",
1752+
*,
1753+
type_comments: bool = False,
1754+
feature_version: None | int | tuple[int, int] = None,
1755+
optimize: Literal[-1, 0, 1, 2] = -1,
1756+
) -> _T: ...
17471757
@overload
17481758
def parse(
17491759
source: str | ReadableBuffer,
1750-
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
1760+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
17511761
mode: Literal["exec"] = "exec",
17521762
*,
17531763
type_comments: bool = False,
@@ -1757,7 +1767,7 @@ if sys.version_info >= (3, 13):
17571767
@overload
17581768
def parse(
17591769
source: str | ReadableBuffer,
1760-
filename: str | ReadableBuffer | os.PathLike[Any],
1770+
filename: str | bytes | os.PathLike[Any],
17611771
mode: Literal["eval"],
17621772
*,
17631773
type_comments: bool = False,
@@ -1767,7 +1777,7 @@ if sys.version_info >= (3, 13):
17671777
@overload
17681778
def parse(
17691779
source: str | ReadableBuffer,
1770-
filename: str | ReadableBuffer | os.PathLike[Any],
1780+
filename: str | bytes | os.PathLike[Any],
17711781
mode: Literal["func_type"],
17721782
*,
17731783
type_comments: bool = False,
@@ -1777,7 +1787,7 @@ if sys.version_info >= (3, 13):
17771787
@overload
17781788
def parse(
17791789
source: str | ReadableBuffer,
1780-
filename: str | ReadableBuffer | os.PathLike[Any],
1790+
filename: str | bytes | os.PathLike[Any],
17811791
mode: Literal["single"],
17821792
*,
17831793
type_comments: bool = False,
@@ -1814,7 +1824,7 @@ if sys.version_info >= (3, 13):
18141824
@overload
18151825
def parse(
18161826
source: str | ReadableBuffer,
1817-
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
1827+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
18181828
mode: str = "exec",
18191829
*,
18201830
type_comments: bool = False,
@@ -1823,10 +1833,19 @@ if sys.version_info >= (3, 13):
18231833
) -> mod: ...
18241834

18251835
else:
1836+
@overload
1837+
def parse(
1838+
source: _T,
1839+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
1840+
mode: Literal["exec", "eval", "func_type", "single"] = "exec",
1841+
*,
1842+
type_comments: bool = False,
1843+
feature_version: None | int | tuple[int, int] = None,
1844+
) -> _T: ...
18261845
@overload
18271846
def parse(
18281847
source: str | ReadableBuffer,
1829-
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
1848+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
18301849
mode: Literal["exec"] = "exec",
18311850
*,
18321851
type_comments: bool = False,
@@ -1835,7 +1854,7 @@ else:
18351854
@overload
18361855
def parse(
18371856
source: str | ReadableBuffer,
1838-
filename: str | ReadableBuffer | os.PathLike[Any],
1857+
filename: str | bytes | os.PathLike[Any],
18391858
mode: Literal["eval"],
18401859
*,
18411860
type_comments: bool = False,
@@ -1844,7 +1863,7 @@ else:
18441863
@overload
18451864
def parse(
18461865
source: str | ReadableBuffer,
1847-
filename: str | ReadableBuffer | os.PathLike[Any],
1866+
filename: str | bytes | os.PathLike[Any],
18481867
mode: Literal["func_type"],
18491868
*,
18501869
type_comments: bool = False,
@@ -1853,7 +1872,7 @@ else:
18531872
@overload
18541873
def parse(
18551874
source: str | ReadableBuffer,
1856-
filename: str | ReadableBuffer | os.PathLike[Any],
1875+
filename: str | bytes | os.PathLike[Any],
18571876
mode: Literal["single"],
18581877
*,
18591878
type_comments: bool = False,
@@ -1886,7 +1905,7 @@ else:
18861905
@overload
18871906
def parse(
18881907
source: str | ReadableBuffer,
1889-
filename: str | ReadableBuffer | os.PathLike[Any] = "<unknown>",
1908+
filename: str | bytes | os.PathLike[Any] = "<unknown>",
18901909
mode: str = "exec",
18911910
*,
18921911
type_comments: bool = False,

0 commit comments

Comments
 (0)