Skip to content

Commit 7e0b499

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@fc11e83
1 parent ce14043 commit 7e0b499

File tree

10 files changed

+137
-16
lines changed

10 files changed

+137
-16
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
286286
def _type_(self) -> type[_CT]: ...
287287
@_type_.setter
288288
def _type_(self, value: type[_CT]) -> None: ...
289-
raw: bytes # Note: only available if _CT == c_char
289+
# Note: only available if _CT == c_char
290+
@property
291+
def raw(self) -> bytes: ...
292+
@raw.setter
293+
def raw(self, value: ReadableBuffer) -> None: ...
290294
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
291295
# TODO These methods cannot be annotated correctly at the moment.
292296
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import sys
12
from collections.abc import Iterable
23
from typing import ClassVar, Literal, NoReturn
34

45
class Quitter:
56
name: str
67
eof: str
78
def __init__(self, name: str, eof: str) -> None: ...
8-
def __call__(self, code: int | None = None) -> NoReturn: ...
9+
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...
910

1011
class _Printer:
1112
MAXLINES: ClassVar[Literal[23]]
1213
def __init__(self, name: str, data: str, files: Iterable[str] = (), dirs: Iterable[str] = ()) -> None: ...
1314
def __call__(self) -> None: ...
1415

1516
class _Helper:
16-
def __call__(self, request: object) -> None: ...
17+
def __call__(self, request: object = ...) -> None: ...

mypy/typeshed/stdlib/asyncio/proactor_events.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePip
6262

6363
class BaseProactorEventLoop(base_events.BaseEventLoop):
6464
def __init__(self, proactor: Any) -> None: ...
65+
async def sock_recv(self, sock: socket, n: int) -> bytes: ...
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import selectors
2+
from socket import socket
23

34
from . import base_events
45

56
__all__ = ("BaseSelectorEventLoop",)
67

78
class BaseSelectorEventLoop(base_events.BaseEventLoop):
89
def __init__(self, selector: selectors.BaseSelector | None = None) -> None: ...
10+
async def sock_recv(self, sock: socket, n: int) -> bytes: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 114 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ruff: noqa: PYI036 # This is the module declaring BaseException
22
import _ast
3+
import _sitebuiltins
34
import _typeshed
45
import sys
56
import types
@@ -46,7 +47,6 @@ from typing import ( # noqa: Y022
4647
Mapping,
4748
MutableMapping,
4849
MutableSequence,
49-
NoReturn,
5050
Protocol,
5151
Sequence,
5252
SupportsAbs,
@@ -64,6 +64,7 @@ from typing import ( # noqa: Y022
6464
from typing_extensions import ( # noqa: Y023
6565
Concatenate,
6666
Literal,
67+
LiteralString,
6768
ParamSpec,
6869
Self,
6970
TypeAlias,
@@ -441,16 +442,31 @@ class str(Sequence[str]):
441442
def __new__(cls, object: object = ...) -> Self: ...
442443
@overload
443444
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
445+
@overload
446+
def capitalize(self: LiteralString) -> LiteralString: ...
447+
@overload
444448
def capitalize(self) -> str: ... # type: ignore[misc]
449+
@overload
450+
def casefold(self: LiteralString) -> LiteralString: ...
451+
@overload
445452
def casefold(self) -> str: ... # type: ignore[misc]
453+
@overload
454+
def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
455+
@overload
446456
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
447457
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
448458
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
449459
def endswith(
450460
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
451461
) -> bool: ...
462+
@overload
463+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
464+
@overload
452465
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
453466
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
467+
@overload
468+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
469+
@overload
454470
def format(self, *args: object, **kwargs: object) -> str: ...
455471
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
456472
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@@ -466,35 +482,99 @@ class str(Sequence[str]):
466482
def isspace(self) -> bool: ...
467483
def istitle(self) -> bool: ...
468484
def isupper(self) -> bool: ...
485+
@overload
486+
def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
487+
@overload
469488
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
489+
@overload
490+
def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
491+
@overload
470492
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
493+
@overload
494+
def lower(self: LiteralString) -> LiteralString: ...
495+
@overload
471496
def lower(self) -> str: ... # type: ignore[misc]
497+
@overload
498+
def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
499+
@overload
472500
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
501+
@overload
502+
def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
503+
@overload
473504
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
474505
if sys.version_info >= (3, 13):
506+
@overload
507+
def replace(
508+
self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
509+
) -> LiteralString: ...
510+
@overload
475511
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
476512
else:
513+
@overload
514+
def replace(
515+
self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
516+
) -> LiteralString: ...
517+
@overload
477518
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
478519
if sys.version_info >= (3, 9):
520+
@overload
521+
def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
522+
@overload
479523
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
524+
@overload
525+
def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
526+
@overload
480527
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
481528

482529
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
483530
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
531+
@overload
532+
def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
533+
@overload
484534
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
535+
@overload
536+
def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
537+
@overload
485538
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
539+
@overload
540+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
541+
@overload
486542
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
543+
@overload
544+
def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
545+
@overload
487546
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
547+
@overload
548+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
549+
@overload
488550
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
551+
@overload
552+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
553+
@overload
489554
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
490555
def startswith(
491556
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
492557
) -> bool: ...
558+
@overload
559+
def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
560+
@overload
493561
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
562+
@overload
563+
def swapcase(self: LiteralString) -> LiteralString: ...
564+
@overload
494565
def swapcase(self) -> str: ... # type: ignore[misc]
566+
@overload
567+
def title(self: LiteralString) -> LiteralString: ...
568+
@overload
495569
def title(self) -> str: ... # type: ignore[misc]
496570
def translate(self, table: _TranslateTable, /) -> str: ...
571+
@overload
572+
def upper(self: LiteralString) -> LiteralString: ...
573+
@overload
497574
def upper(self) -> str: ... # type: ignore[misc]
575+
@overload
576+
def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
577+
@overload
498578
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
499579
@staticmethod
500580
@overload
@@ -505,21 +585,39 @@ class str(Sequence[str]):
505585
@staticmethod
506586
@overload
507587
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
588+
@overload
589+
def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
590+
@overload
508591
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
509592
# Incompatible with Sequence.__contains__
510593
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
511594
def __eq__(self, value: object, /) -> bool: ...
512595
def __ge__(self, value: str, /) -> bool: ...
513-
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
596+
@overload
597+
def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
598+
@overload
599+
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
514600
def __gt__(self, value: str, /) -> bool: ...
515601
def __hash__(self) -> int: ...
602+
@overload
603+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
604+
@overload
516605
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
517606
def __le__(self, value: str, /) -> bool: ...
518607
def __len__(self) -> int: ...
519608
def __lt__(self, value: str, /) -> bool: ...
609+
@overload
610+
def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
611+
@overload
520612
def __mod__(self, value: Any, /) -> str: ...
613+
@overload
614+
def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
615+
@overload
521616
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
522617
def __ne__(self, value: object, /) -> bool: ...
618+
@overload
619+
def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
620+
@overload
523621
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
524622
def __getnewargs__(self) -> tuple[str]: ...
525623

@@ -1264,8 +1362,10 @@ def compile(
12641362
*,
12651363
_feature_version: int = -1,
12661364
) -> Any: ...
1267-
def copyright() -> None: ...
1268-
def credits() -> None: ...
1365+
1366+
copyright: _sitebuiltins._Printer
1367+
credits: _sitebuiltins._Printer
1368+
12691369
def delattr(obj: object, name: str, /) -> None: ...
12701370
def dir(o: object = ..., /) -> list[str]: ...
12711371
@overload
@@ -1320,7 +1420,7 @@ else:
13201420
/,
13211421
) -> None: ...
13221422

1323-
def exit(code: sys._ExitCode = None) -> NoReturn: ...
1423+
exit: _sitebuiltins.Quitter
13241424

13251425
class filter(Generic[_T]):
13261426
@overload
@@ -1354,7 +1454,9 @@ def getattr(o: object, name: str, default: _T, /) -> Any | _T: ...
13541454
def globals() -> dict[str, Any]: ...
13551455
def hasattr(obj: object, name: str, /) -> bool: ...
13561456
def hash(obj: object, /) -> int: ...
1357-
def help(request: object = ...) -> None: ...
1457+
1458+
help: _sitebuiltins._Helper
1459+
13581460
def hex(number: int | SupportsIndex, /) -> str: ...
13591461
def id(obj: object, /) -> int: ...
13601462
def input(prompt: object = "", /) -> str: ...
@@ -1380,7 +1482,9 @@ else:
13801482
def isinstance(obj: object, class_or_tuple: _ClassInfo, /) -> bool: ...
13811483
def issubclass(cls: type, class_or_tuple: _ClassInfo, /) -> bool: ...
13821484
def len(obj: Sized, /) -> int: ...
1383-
def license() -> None: ...
1485+
1486+
license: _sitebuiltins._Printer
1487+
13841488
def locals() -> dict[str, Any]: ...
13851489

13861490
class map(Generic[_S]):
@@ -1623,7 +1727,8 @@ def pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co: ...
16231727
def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
16241728
@overload
16251729
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ...
1626-
def quit(code: sys._ExitCode = None) -> NoReturn: ...
1730+
1731+
quit: _sitebuiltins.Quitter
16271732

16281733
class reversed(Generic[_T]):
16291734
@overload
@@ -1673,7 +1778,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
16731778
# without creating many false-positive errors (see #7578).
16741779
# Instead, we special-case the most common examples of this: bool and literal integers.
16751780
@overload
1676-
def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
1781+
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
16771782
@overload
16781783
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
16791784
@overload

mypy/typeshed/stdlib/ctypes/__init__.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ArgumentError(Exception): ...
4747

4848
class CDLL:
4949
_func_flags_: ClassVar[int]
50-
_func_restype_: ClassVar[_CDataType]
50+
_func_restype_: ClassVar[type[_CDataType]]
5151
_name: str
5252
_handle: int
5353
_FuncPtr: type[_FuncPointer]
@@ -202,7 +202,10 @@ if sys.platform == "win32":
202202
class HRESULT(_SimpleCData[int]): ... # TODO undocumented
203203

204204
if sys.version_info >= (3, 12):
205-
c_time_t: type[c_int32 | c_int64] # alias for one or the other at runtime
205+
# At runtime, this is an alias for either c_int32 or c_int64,
206+
# which are themselves an alias for one of c_short, c_int, c_long, or c_longlong
207+
# This covers all our bases.
208+
c_time_t: type[c_int32 | c_int64 | c_short | c_int | c_long | c_longlong]
206209

207210
class py_object(_CanCastTo, _SimpleCData[_T]): ...
208211

mypy/typeshed/stdlib/fractions.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class Fraction(Rational):
2727
@overload
2828
def __new__(cls, numerator: int | Rational = 0, denominator: int | Rational | None = None) -> Self: ...
2929
@overload
30-
def __new__(cls, value: float | Decimal | str, /) -> Self: ...
30+
def __new__(cls, numerator: float | Decimal | str) -> Self: ...
3131

3232
if sys.version_info >= (3, 14):
3333
@overload
34-
def __new__(cls, value: _ConvertibleToIntegerRatio) -> Self: ...
34+
def __new__(cls, numerator: _ConvertibleToIntegerRatio) -> Self: ...
3535

3636
@classmethod
3737
def from_float(cls, f: float) -> Self: ...

mypy/typeshed/stdlib/optparse.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ class Values:
182182
def ensure_value(self, attr: str, value): ...
183183
def read_file(self, filename: str, mode: str = "careful") -> None: ...
184184
def read_module(self, modname: str, mode: str = "careful") -> None: ...
185+
# __getattr__ doesn't exist, but anything passed as a default to __init__
186+
# is set on the instance.
185187
def __getattr__(self, name: str): ...
186188
def __setattr__(self, name: str, value, /) -> None: ...
187189
def __eq__(self, other: object) -> bool: ...

mypy/typeshed/stdlib/os/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ if sys.platform == "linux" and sys.version_info >= (3, 12):
231231
"CLONE_NEWNET",
232232
"CLONE_NEWNS",
233233
"CLONE_NEWPID",
234+
"CLONE_NEWTIME",
234235
"CLONE_NEWUSER",
235236
"CLONE_NEWUTS",
236237
"CLONE_SIGHAND",

mypy/typeshed/stdlib/traceback.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ if sys.version_info >= (3, 11):
115115
class TracebackException:
116116
__cause__: TracebackException
117117
__context__: TracebackException
118+
if sys.version_info >= (3, 11):
119+
exceptions: list[TracebackException] | None
118120
__suppress_context__: bool
119121
stack: StackSummary
120122
filename: str

0 commit comments

Comments
 (0)