Skip to content

Commit 5ffa6dd

Browse files
Sync typeshed (#16918)
Source commit: python/typeshed@48a0497
1 parent c26f129 commit 5ffa6dd

36 files changed

+653
-553
lines changed

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PyCF_ONLY_AST: Literal[1024]
66
PyCF_TYPE_COMMENTS: Literal[4096]
77
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
88

9+
# Alias used for fields that must always be valid identifiers
10+
# A string `x` counts as a valid identifier if both the following are True
11+
# (1) `x.isidentifier()` evaluates to `True`
12+
# (2) `keyword.iskeyword(x)` evaluates to `False`
913
_Identifier: typing_extensions.TypeAlias = str
1014

1115
class AST:
@@ -499,7 +503,7 @@ class keyword(AST):
499503
class alias(AST):
500504
if sys.version_info >= (3, 10):
501505
__match_args__ = ("name", "asname")
502-
name: _Identifier
506+
name: str
503507
asname: _Identifier | None
504508

505509
class withitem(AST):

mypy/typeshed/stdlib/_curses.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,5 +553,6 @@ if sys.platform != "win32":
553553
major: int
554554
minor: int
555555
patch: int
556+
556557
ncurses_version: _ncurses_version
557558
window = _CursesWindow # undocumented

mypy/typeshed/stdlib/_msi.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if sys.platform == "win32":
4545
# Don't exist at runtime
4646
__new__: None # type: ignore[assignment]
4747
__init__: None # type: ignore[assignment]
48+
4849
def UuidCreate() -> str: ...
4950
def FCICreate(__cabname: str, __files: list[str]) -> None: ...
5051
def OpenDatabase(__path: str, __persist: int) -> _Database: ...

mypy/typeshed/stdlib/_thread.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def get_native_id() -> int: ... # only available on some platforms
3232
class _ExceptHookArgs(structseq[Any], tuple[type[BaseException], BaseException | None, TracebackType | None, Thread | None]):
3333
if sys.version_info >= (3, 10):
3434
__match_args__: Final = ("exc_type", "exc_value", "exc_traceback", "thread")
35+
3536
@property
3637
def exc_type(self) -> type[BaseException]: ...
3738
@property

mypy/typeshed/stdlib/asyncio/sslproto.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if sys.version_info >= (3, 11):
2525
STATE_CON_MADE: str
2626
STATE_EOF: str
2727
STATE_CON_LOST: str
28+
2829
def add_flowcontrol_defaults(high: int | None, low: int | None, kb: int) -> tuple[int, int]: ...
2930

3031
else:
@@ -155,9 +156,10 @@ class SSLProtocol(_SSLProtocolBase):
155156
def _check_handshake_timeout(self) -> None: ...
156157
def _on_handshake_complete(self, handshake_exc: BaseException | None) -> None: ...
157158
def _fatal_error(self, exc: BaseException, message: str = "Fatal error on transport") -> None: ...
158-
def _abort(self) -> None: ...
159159
if sys.version_info >= (3, 11):
160+
def _abort(self, exc: BaseException | None) -> None: ...
160161
def get_buffer(self, n: int) -> memoryview: ...
161162
else:
163+
def _abort(self) -> None: ...
162164
def _finalize(self) -> None: ...
163165
def _process_write_backlog(self) -> None: ...

mypy/typeshed/stdlib/asyncio/unix_events.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ if sys.platform != "win32":
9696
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
9797
def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ...
9898
def remove_child_handler(self, pid: int) -> bool: ...
99+
99100
else:
100101
class SafeChildWatcher(BaseChildWatcher):
101102
def __enter__(self) -> Self: ...
@@ -120,6 +121,7 @@ if sys.platform != "win32":
120121
else:
121122
def get_child_watcher(self) -> AbstractChildWatcher: ...
122123
def set_child_watcher(self, watcher: AbstractChildWatcher | None) -> None: ...
124+
123125
SelectorEventLoop = _UnixSelectorEventLoop
124126

125127
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
@@ -136,6 +138,7 @@ if sys.platform != "win32":
136138
def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ...
137139
def remove_child_handler(self, pid: int) -> bool: ...
138140
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
141+
139142
else:
140143
class MultiLoopChildWatcher(AbstractChildWatcher):
141144
def is_active(self) -> bool: ...

mypy/typeshed/stdlib/asyncio/windows_events.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if sys.platform == "win32":
6969
def recvfrom_into(
7070
self, conn: socket.socket, buf: WriteableBuffer, flags: int = 0
7171
) -> futures.Future[tuple[int, socket._RetAddress]]: ...
72+
7273
SelectorEventLoop = _WindowsSelectorEventLoop
7374

7475
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
@@ -80,4 +81,5 @@ if sys.platform == "win32":
8081
_loop_factory: ClassVar[type[ProactorEventLoop]]
8182
def get_child_watcher(self) -> NoReturn: ...
8283
def set_child_watcher(self, watcher: Any) -> NoReturn: ...
84+
8385
DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy

mypy/typeshed/stdlib/calendar.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class HTMLCalendar(Calendar):
124124
def formatyear(self, theyear: int, width: int = 3) -> str: ...
125125
def formatyearpage(
126126
self, theyear: int, width: int = 3, css: str | None = "calendar.css", encoding: str | None = None
127-
) -> str: ...
127+
) -> bytes: ...
128128

129129
class different_locale:
130130
def __init__(self, locale: _LocaleType) -> None: ...
@@ -166,6 +166,7 @@ if sys.version_info >= (3, 12):
166166
OCTOBER: Literal[10]
167167
NOVEMBER: Literal[11]
168168
DECEMBER: Literal[12]
169+
169170
JANUARY = Month.JANUARY
170171
FEBRUARY = Month.FEBRUARY
171172
MARCH = Month.MARCH
@@ -187,6 +188,7 @@ if sys.version_info >= (3, 12):
187188
FRIDAY: Literal[4]
188189
SATURDAY: Literal[5]
189190
SUNDAY: Literal[6]
191+
190192
MONDAY = Day.MONDAY
191193
TUESDAY = Day.TUESDAY
192194
WEDNESDAY = Day.WEDNESDAY

mypy/typeshed/stdlib/contextlib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class closing(AbstractContextManager[_SupportsCloseT]):
118118
if sys.version_info >= (3, 10):
119119
class _SupportsAclose(Protocol):
120120
def aclose(self) -> Awaitable[object]: ...
121+
121122
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
122123

123124
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):

mypy/typeshed/stdlib/dbm/gnu.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ if sys.platform != "win32":
3737
# Don't exist at runtime
3838
__new__: None # type: ignore[assignment]
3939
__init__: None # type: ignore[assignment]
40+
4041
def open(__filename: str, __flags: str = "r", __mode: int = 0o666) -> _gdbm: ...

mypy/typeshed/stdlib/dbm/ndbm.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ if sys.platform != "win32":
3333
# Don't exist at runtime
3434
__new__: None # type: ignore[assignment]
3535
__init__: None # type: ignore[assignment]
36+
3637
def open(__filename: str, __flags: str = "r", __mode: int = 0o666) -> _dbm: ...

mypy/typeshed/stdlib/enum.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ if sys.version_info >= (3, 11):
175175
name: str
176176
clsname: str
177177
member: Enum | None
178+
178179
_magic_enum_attr = property
179180
else:
180181
_magic_enum_attr = types.DynamicClassAttribute
@@ -261,6 +262,7 @@ if sys.version_info >= (3, 11):
261262
CONTINUOUS: str
262263
NAMED_FLAGS: str
263264
UNIQUE: str
265+
264266
CONTINUOUS = EnumCheck.CONTINUOUS
265267
NAMED_FLAGS = EnumCheck.NAMED_FLAGS
266268
UNIQUE = EnumCheck.UNIQUE
@@ -274,6 +276,7 @@ if sys.version_info >= (3, 11):
274276
CONFORM: str
275277
EJECT: str
276278
KEEP: str
279+
277280
STRICT = FlagBoundary.STRICT
278281
CONFORM = FlagBoundary.CONFORM
279282
EJECT = FlagBoundary.EJECT

mypy/typeshed/stdlib/ftplib.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FTP:
3131
sock: socket | None
3232
welcome: str | None
3333
passiveserver: int
34-
timeout: int
34+
timeout: float | None
3535
af: int
3636
lastresp: str
3737
file: TextIO | None
@@ -48,7 +48,7 @@ class FTP:
4848
user: str = "",
4949
passwd: str = "",
5050
acct: str = "",
51-
timeout: float = ...,
51+
timeout: float | None = ...,
5252
source_address: tuple[str, int] | None = None,
5353
*,
5454
encoding: str = "utf-8",
@@ -60,7 +60,7 @@ class FTP:
6060
user: str = "",
6161
passwd: str = "",
6262
acct: str = "",
63-
timeout: float = ...,
63+
timeout: float | None = ...,
6464
source_address: tuple[str, int] | None = None,
6565
) -> None: ...
6666

@@ -127,7 +127,7 @@ class FTP_TLS(FTP):
127127
acct: str = "",
128128
*,
129129
context: SSLContext | None = None,
130-
timeout: float = ...,
130+
timeout: float | None = ...,
131131
source_address: tuple[str, int] | None = None,
132132
encoding: str = "utf-8",
133133
) -> None: ...
@@ -141,7 +141,7 @@ class FTP_TLS(FTP):
141141
keyfile: str | None = None,
142142
certfile: str | None = None,
143143
context: SSLContext | None = None,
144-
timeout: float = ...,
144+
timeout: float | None = ...,
145145
source_address: tuple[str, int] | None = None,
146146
*,
147147
encoding: str = "utf-8",
@@ -156,7 +156,7 @@ class FTP_TLS(FTP):
156156
keyfile: str | None = None,
157157
certfile: str | None = None,
158158
context: SSLContext | None = None,
159-
timeout: float = ...,
159+
timeout: float | None = ...,
160160
source_address: tuple[str, int] | None = None,
161161
) -> None: ...
162162
ssl_version: int

mypy/typeshed/stdlib/grp.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if sys.platform != "win32":
77
class struct_group(structseq[Any], tuple[str, str | None, int, list[str]]):
88
if sys.version_info >= (3, 10):
99
__match_args__: Final = ("gr_name", "gr_passwd", "gr_gid", "gr_mem")
10+
1011
@property
1112
def gr_name(self) -> str: ...
1213
@property

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PackageNotFoundError(ModuleNotFoundError):
4343
if sys.version_info >= (3, 11):
4444
class DeprecatedTuple:
4545
def __getitem__(self, item: int) -> str: ...
46+
4647
_EntryPointBase = DeprecatedTuple
4748
else:
4849
class _EntryPointBase(NamedTuple):

mypy/typeshed/stdlib/inspect.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ if sys.version_info < (3, 11):
430430
varargs: str | None
431431
keywords: str | None
432432
defaults: tuple[Any, ...]
433+
433434
def getargspec(func: object) -> ArgSpec: ...
434435

435436
class FullArgSpec(NamedTuple):

mypy/typeshed/stdlib/io.pyi

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from _typeshed import FileDescriptorOrPath, ReadableBuffer, WriteableBuffer
66
from collections.abc import Callable, Iterable, Iterator
77
from os import _Opener
88
from types import TracebackType
9-
from typing import IO, Any, BinaryIO, Literal, TextIO, TypeVar, overload
9+
from typing import IO, Any, BinaryIO, Literal, Protocol, TextIO, TypeVar, overload, type_check_only
1010
from typing_extensions import Self
1111

1212
__all__ = [
@@ -94,7 +94,10 @@ class BufferedIOBase(IOBase):
9494

9595
class FileIO(RawIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes
9696
mode: str
97-
name: FileDescriptorOrPath
97+
# The type of "name" equals the argument passed in to the constructor,
98+
# but that can make FileIO incompatible with other I/O types that assume
99+
# "name" is a str. In the future, making FileIO generic might help.
100+
name: Any
98101
def __init__(
99102
self, file: FileDescriptorOrPath, mode: str = ..., closefd: bool = ..., opener: _Opener | None = ...
100103
) -> None: ...
@@ -146,16 +149,43 @@ class TextIOBase(IOBase):
146149
def readlines(self, __hint: int = -1) -> list[str]: ... # type: ignore[override]
147150
def read(self, __size: int | None = ...) -> str: ...
148151

152+
@type_check_only
153+
class _WrappedBuffer(Protocol):
154+
# "name" is wrapped by TextIOWrapper. Its type is inconsistent between
155+
# the various I/O types, see the comments on TextIOWrapper.name and
156+
# TextIO.name.
157+
@property
158+
def name(self) -> Any: ...
159+
@property
160+
def closed(self) -> bool: ...
161+
def read(self, size: int = ..., /) -> ReadableBuffer: ...
162+
# Optional: def read1(self, size: int, /) -> ReadableBuffer: ...
163+
def write(self, b: bytes, /) -> object: ...
164+
def flush(self) -> object: ...
165+
def close(self) -> object: ...
166+
def seekable(self) -> bool: ...
167+
def readable(self) -> bool: ...
168+
def writable(self) -> bool: ...
169+
def truncate(self, size: int, /) -> int: ...
170+
def fileno(self) -> int: ...
171+
def isatty(self) -> int: ...
172+
# Optional: Only needs to be present if seekable() returns True.
173+
# def seek(self, offset: Literal[0], whence: Literal[2]) -> int: ...
174+
# def tell(self) -> int: ...
175+
176+
# TODO: Should be generic over the buffer type, but needs to wait for
177+
# TypeVar defaults.
149178
class TextIOWrapper(TextIOBase, TextIO): # type: ignore[misc] # incompatible definitions of write in the base classes
150179
def __init__(
151180
self,
152-
buffer: IO[bytes],
181+
buffer: _WrappedBuffer,
153182
encoding: str | None = ...,
154183
errors: str | None = ...,
155184
newline: str | None = ...,
156185
line_buffering: bool = ...,
157186
write_through: bool = ...,
158187
) -> None: ...
188+
# Equals the "buffer" argument passed in to the constructor.
159189
@property
160190
def buffer(self) -> BinaryIO: ...
161191
@property
@@ -180,7 +210,11 @@ class TextIOWrapper(TextIOBase, TextIO): # type: ignore[misc] # incompatible d
180210
def writelines(self, __lines: Iterable[str]) -> None: ... # type: ignore[override]
181211
def readline(self, __size: int = -1) -> str: ... # type: ignore[override]
182212
def readlines(self, __hint: int = -1) -> list[str]: ... # type: ignore[override]
183-
def seek(self, __cookie: int, __whence: int = 0) -> int: ... # stubtest needs this
213+
# Equals the "buffer" argument passed in to the constructor.
214+
def detach(self) -> BinaryIO: ...
215+
# TextIOWrapper's version of seek only supports a limited subset of
216+
# operations.
217+
def seek(self, __cookie: int, __whence: int = 0) -> int: ...
184218

185219
class StringIO(TextIOWrapper):
186220
def __init__(self, initial_value: str | None = ..., newline: str | None = ...) -> None: ...

mypy/typeshed/stdlib/msilib/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if sys.platform == "win32":
5656
def gen_id(self, file: str) -> str: ...
5757
def append(self, full: str, file: str, logical: str) -> tuple[int, str]: ...
5858
def commit(self, db: _Database) -> None: ...
59+
5960
_directories: set[str]
6061

6162
class Directory:

mypy/typeshed/stdlib/multiprocessing/reduction.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ class AbstractReducer(metaclass=ABCMeta):
8686
sendfds = _sendfds
8787
recvfds = _recvfds
8888
DupFd = _DupFd
89+
8990
def __init__(self, *args: Unused) -> None: ...

mypy/typeshed/stdlib/os/__init__.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ class stat_result(structseq[float], tuple[int, int, int, int, int, int, int, flo
341341
# More items may be added at the end by some implementations.
342342
if sys.version_info >= (3, 10):
343343
__match_args__: Final = ("st_mode", "st_ino", "st_dev", "st_nlink", "st_uid", "st_gid", "st_size")
344+
344345
@property
345346
def st_mode(self) -> int: ... # protection bits,
346347
@property
@@ -446,6 +447,7 @@ class statvfs_result(structseq[int], tuple[int, int, int, int, int, int, int, in
446447
"f_flag",
447448
"f_namemax",
448449
)
450+
449451
@property
450452
def f_bsize(self) -> int: ...
451453
@property
@@ -488,6 +490,7 @@ def umask(__mask: int) -> int: ...
488490
class uname_result(structseq[str], tuple[str, str, str, str, str]):
489491
if sys.version_info >= (3, 10):
490492
__match_args__: Final = ("sysname", "nodename", "release", "version", "machine")
493+
491494
@property
492495
def sysname(self) -> str: ...
493496
@property
@@ -704,6 +707,7 @@ if sys.platform != "win32":
704707
class terminal_size(structseq[int], tuple[int, int]):
705708
if sys.version_info >= (3, 10):
706709
__match_args__: Final = ("columns", "lines")
710+
707711
@property
708712
def columns(self) -> int: ...
709713
@property
@@ -925,6 +929,7 @@ def system(command: StrOrBytesPath) -> int: ...
925929
class times_result(structseq[float], tuple[float, float, float, float, float]):
926930
if sys.version_info >= (3, 10):
927931
__match_args__: Final = ("user", "system", "children_user", "children_system", "elapsed")
932+
928933
@property
929934
def user(self) -> float: ...
930935
@property
@@ -962,6 +967,7 @@ else:
962967
class waitid_result(structseq[int], tuple[int, int, int, int, int]):
963968
if sys.version_info >= (3, 10):
964969
__match_args__: Final = ("si_pid", "si_uid", "si_signo", "si_status", "si_code")
970+
965971
@property
966972
def si_pid(self) -> int: ...
967973
@property
@@ -1022,6 +1028,7 @@ if sys.platform != "win32":
10221028
class sched_param(structseq[int], tuple[int]):
10231029
if sys.version_info >= (3, 10):
10241030
__match_args__: Final = ("sched_priority",)
1031+
10251032
def __new__(cls, sched_priority: int) -> Self: ...
10261033
@property
10271034
def sched_priority(self) -> int: ...

0 commit comments

Comments
 (0)