Skip to content

Commit c4a9697

Browse files
hauntsaninjaJukkaL
authored andcommitted
Sync typeshed (#12596)
Source commit: python/typeshed@d09689f Co-authored-by: hauntsaninja <>
1 parent d96330b commit c4a9697

11 files changed

+300
-133
lines changed

mypy/typeshed/stdlib/_pydecimal.pyi

+82
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,85 @@
1+
import sys
2+
13
# This is a slight lie, the implementations aren't exactly identical
24
# However, in all likelihood, the differences are inconsequential
35
from decimal import *
6+
7+
if sys.version_info >= (3, 7):
8+
__all__ = [
9+
"Decimal",
10+
"Context",
11+
"DecimalTuple",
12+
"DefaultContext",
13+
"BasicContext",
14+
"ExtendedContext",
15+
"DecimalException",
16+
"Clamped",
17+
"InvalidOperation",
18+
"DivisionByZero",
19+
"Inexact",
20+
"Rounded",
21+
"Subnormal",
22+
"Overflow",
23+
"Underflow",
24+
"FloatOperation",
25+
"DivisionImpossible",
26+
"InvalidContext",
27+
"ConversionSyntax",
28+
"DivisionUndefined",
29+
"ROUND_DOWN",
30+
"ROUND_HALF_UP",
31+
"ROUND_HALF_EVEN",
32+
"ROUND_CEILING",
33+
"ROUND_FLOOR",
34+
"ROUND_UP",
35+
"ROUND_HALF_DOWN",
36+
"ROUND_05UP",
37+
"setcontext",
38+
"getcontext",
39+
"localcontext",
40+
"MAX_PREC",
41+
"MAX_EMAX",
42+
"MIN_EMIN",
43+
"MIN_ETINY",
44+
"HAVE_THREADS",
45+
"HAVE_CONTEXTVAR",
46+
]
47+
else:
48+
__all__ = [
49+
"Decimal",
50+
"Context",
51+
"DecimalTuple",
52+
"DefaultContext",
53+
"BasicContext",
54+
"ExtendedContext",
55+
"DecimalException",
56+
"Clamped",
57+
"InvalidOperation",
58+
"DivisionByZero",
59+
"Inexact",
60+
"Rounded",
61+
"Subnormal",
62+
"Overflow",
63+
"Underflow",
64+
"FloatOperation",
65+
"DivisionImpossible",
66+
"InvalidContext",
67+
"ConversionSyntax",
68+
"DivisionUndefined",
69+
"ROUND_DOWN",
70+
"ROUND_HALF_UP",
71+
"ROUND_HALF_EVEN",
72+
"ROUND_CEILING",
73+
"ROUND_FLOOR",
74+
"ROUND_UP",
75+
"ROUND_HALF_DOWN",
76+
"ROUND_05UP",
77+
"setcontext",
78+
"getcontext",
79+
"localcontext",
80+
"MAX_PREC",
81+
"MAX_EMAX",
82+
"MIN_EMIN",
83+
"MIN_ETINY",
84+
"HAVE_THREADS",
85+
]

mypy/typeshed/stdlib/asyncio/streams.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
159159
class StreamWriter:
160160
def __init__(
161161
self,
162-
transport: transports.BaseTransport,
162+
transport: transports.WriteTransport,
163163
protocol: protocols.BaseProtocol,
164164
reader: StreamReader | None,
165165
loop: events.AbstractEventLoop,
166166
) -> None: ...
167167
@property
168-
def transport(self) -> transports.BaseTransport: ...
168+
def transport(self) -> transports.WriteTransport: ...
169169
def write(self, data: bytes) -> None: ...
170170
def writelines(self, data: Iterable[bytes]) -> None: ...
171171
def write_eof(self) -> None: ...

mypy/typeshed/stdlib/asyncio/transports.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class ReadTransport(BaseTransport):
2727
class WriteTransport(BaseTransport):
2828
def set_write_buffer_limits(self, high: int | None = ..., low: int | None = ...) -> None: ...
2929
def get_write_buffer_size(self) -> int: ...
30+
if sys.version_info >= (3, 9):
31+
def get_write_buffer_limits(self) -> tuple[int, int]: ...
32+
3033
def write(self, data: Any) -> None: ...
3134
def writelines(self, list_of_data: list[Any]) -> None: ...
3235
def write_eof(self) -> None: ...

mypy/typeshed/stdlib/base64.pyi

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import ReadableBuffer
23
from typing import IO
34

45
if sys.version_info >= (3, 10):
@@ -46,30 +47,30 @@ else:
4647
"urlsafe_b64decode",
4748
]
4849

49-
def b64encode(s: bytes, altchars: bytes | None = ...) -> bytes: ...
50-
def b64decode(s: str | bytes, altchars: bytes | None = ..., validate: bool = ...) -> bytes: ...
51-
def standard_b64encode(s: bytes) -> bytes: ...
52-
def standard_b64decode(s: str | bytes) -> bytes: ...
53-
def urlsafe_b64encode(s: bytes) -> bytes: ...
54-
def urlsafe_b64decode(s: str | bytes) -> bytes: ...
55-
def b32encode(s: bytes) -> bytes: ...
56-
def b32decode(s: str | bytes, casefold: bool = ..., map01: bytes | None = ...) -> bytes: ...
57-
def b16encode(s: bytes) -> bytes: ...
58-
def b16decode(s: str | bytes, casefold: bool = ...) -> bytes: ...
50+
def b64encode(s: ReadableBuffer, altchars: ReadableBuffer | None = ...) -> bytes: ...
51+
def b64decode(s: str | ReadableBuffer, altchars: ReadableBuffer | None = ..., validate: bool = ...) -> bytes: ...
52+
def standard_b64encode(s: ReadableBuffer) -> bytes: ...
53+
def standard_b64decode(s: str | ReadableBuffer) -> bytes: ...
54+
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
55+
def urlsafe_b64decode(s: str | ReadableBuffer) -> bytes: ...
56+
def b32encode(s: ReadableBuffer) -> bytes: ...
57+
def b32decode(s: str | ReadableBuffer, casefold: bool = ..., map01: bytes | None = ...) -> bytes: ...
58+
def b16encode(s: ReadableBuffer) -> bytes: ...
59+
def b16decode(s: str | ReadableBuffer, casefold: bool = ...) -> bytes: ...
5960

6061
if sys.version_info >= (3, 10):
61-
def b32hexencode(s: bytes) -> bytes: ...
62-
def b32hexdecode(s: str | bytes, casefold: bool = ...) -> bytes: ...
62+
def b32hexencode(s: ReadableBuffer) -> bytes: ...
63+
def b32hexdecode(s: str | ReadableBuffer, casefold: bool = ...) -> bytes: ...
6364

64-
def a85encode(b: bytes, *, foldspaces: bool = ..., wrapcol: int = ..., pad: bool = ..., adobe: bool = ...) -> bytes: ...
65-
def a85decode(b: str | bytes, *, foldspaces: bool = ..., adobe: bool = ..., ignorechars: str | bytes = ...) -> bytes: ...
66-
def b85encode(b: bytes, pad: bool = ...) -> bytes: ...
67-
def b85decode(b: str | bytes) -> bytes: ...
65+
def a85encode(b: ReadableBuffer, *, foldspaces: bool = ..., wrapcol: int = ..., pad: bool = ..., adobe: bool = ...) -> bytes: ...
66+
def a85decode(b: str | ReadableBuffer, *, foldspaces: bool = ..., adobe: bool = ..., ignorechars: str | bytes = ...) -> bytes: ...
67+
def b85encode(b: ReadableBuffer, pad: bool = ...) -> bytes: ...
68+
def b85decode(b: str | ReadableBuffer) -> bytes: ...
6869
def decode(input: IO[bytes], output: IO[bytes]) -> None: ...
6970
def encode(input: IO[bytes], output: IO[bytes]) -> None: ...
70-
def encodebytes(s: bytes) -> bytes: ...
71-
def decodebytes(s: bytes) -> bytes: ...
71+
def encodebytes(s: ReadableBuffer) -> bytes: ...
72+
def decodebytes(s: ReadableBuffer) -> bytes: ...
7273

7374
if sys.version_info < (3, 9):
74-
def encodestring(s: bytes) -> bytes: ...
75-
def decodestring(s: bytes) -> bytes: ...
75+
def encodestring(s: ReadableBuffer) -> bytes: ...
76+
def decodestring(s: ReadableBuffer) -> bytes: ...

mypy/typeshed/stdlib/builtins.pyi

+36-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ from typing import (
5252
SupportsInt,
5353
SupportsRound,
5454
TypeVar,
55-
Union,
5655
overload,
5756
)
5857
from typing_extensions import Literal, SupportsIndex, TypeGuard, final
@@ -1747,19 +1746,45 @@ if sys.version_info >= (3, 10):
17471746
class EncodingWarning(Warning): ...
17481747

17491748
if sys.version_info >= (3, 11):
1750-
_SplitCondition = Union[type[BaseException], tuple[type[BaseException], ...], Callable[[BaseException], bool]]
1749+
_BaseExceptionT_co = TypeVar("_BaseExceptionT_co", bound=BaseException, covariant=True)
1750+
_BaseExceptionT = TypeVar("_BaseExceptionT", bound=BaseException)
1751+
_ExceptionT_co = TypeVar("_ExceptionT_co", bound=Exception, covariant=True)
1752+
_ExceptionT = TypeVar("_ExceptionT", bound=Exception)
17511753

1752-
class BaseExceptionGroup(BaseException):
1753-
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[BaseException]) -> Self: ...
1754+
class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
1755+
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ...
17541756
@property
17551757
def message(self) -> str: ...
17561758
@property
1757-
def exceptions(self) -> tuple[BaseException, ...]: ...
1758-
def subgroup(self: Self, __condition: _SplitCondition) -> Self | None: ...
1759-
def split(self: Self, __condition: _SplitCondition) -> tuple[Self | None, Self | None]: ...
1760-
def derive(self: Self, __excs: Sequence[BaseException]) -> Self: ...
1759+
def exceptions(self) -> tuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]: ...
1760+
@overload
1761+
def subgroup(
1762+
self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
1763+
) -> BaseExceptionGroup[_BaseExceptionT] | None: ...
1764+
@overload
1765+
def subgroup(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> Self | None: ...
1766+
@overload
1767+
def split(
1768+
self: Self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
1769+
) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]: ...
1770+
@overload
1771+
def split(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> tuple[Self | None, Self | None]: ...
1772+
def derive(self: Self, __excs: Sequence[_BaseExceptionT_co]) -> Self: ...
17611773

1762-
class ExceptionGroup(BaseExceptionGroup, Exception):
1763-
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[Exception]) -> Self: ...
1774+
class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
1775+
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ...
17641776
@property
1765-
def exceptions(self) -> tuple[Exception, ...]: ...
1777+
def exceptions(self) -> tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]: ...
1778+
# We accept a narrower type, but that's OK.
1779+
@overload # type: ignore[override]
1780+
def subgroup(
1781+
self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
1782+
) -> ExceptionGroup[_ExceptionT] | None: ...
1783+
@overload
1784+
def subgroup(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> Self | None: ...
1785+
@overload # type: ignore[override]
1786+
def split(
1787+
self: Self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
1788+
) -> tuple[ExceptionGroup[_ExceptionT] | None, Self | None]: ...
1789+
@overload
1790+
def split(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> tuple[Self | None, Self | None]: ...

mypy/typeshed/stdlib/calendar.pyi

+61-26
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,67 @@ from collections.abc import Iterable, Sequence
44
from time import struct_time
55
from typing_extensions import Literal
66

7-
__all__ = [
8-
"IllegalMonthError",
9-
"IllegalWeekdayError",
10-
"setfirstweekday",
11-
"firstweekday",
12-
"isleap",
13-
"leapdays",
14-
"weekday",
15-
"monthrange",
16-
"monthcalendar",
17-
"prmonth",
18-
"month",
19-
"prcal",
20-
"calendar",
21-
"timegm",
22-
"month_name",
23-
"month_abbr",
24-
"day_name",
25-
"day_abbr",
26-
"Calendar",
27-
"TextCalendar",
28-
"HTMLCalendar",
29-
"LocaleTextCalendar",
30-
"LocaleHTMLCalendar",
31-
"weekheader",
32-
]
7+
if sys.version_info >= (3, 10):
8+
__all__ = [
9+
"IllegalMonthError",
10+
"IllegalWeekdayError",
11+
"setfirstweekday",
12+
"firstweekday",
13+
"isleap",
14+
"leapdays",
15+
"weekday",
16+
"monthrange",
17+
"monthcalendar",
18+
"prmonth",
19+
"month",
20+
"prcal",
21+
"calendar",
22+
"timegm",
23+
"month_name",
24+
"month_abbr",
25+
"day_name",
26+
"day_abbr",
27+
"Calendar",
28+
"TextCalendar",
29+
"HTMLCalendar",
30+
"LocaleTextCalendar",
31+
"LocaleHTMLCalendar",
32+
"weekheader",
33+
"FRIDAY",
34+
"MONDAY",
35+
"SATURDAY",
36+
"SUNDAY",
37+
"THURSDAY",
38+
"TUESDAY",
39+
"WEDNESDAY",
40+
]
41+
else:
42+
__all__ = [
43+
"IllegalMonthError",
44+
"IllegalWeekdayError",
45+
"setfirstweekday",
46+
"firstweekday",
47+
"isleap",
48+
"leapdays",
49+
"weekday",
50+
"monthrange",
51+
"monthcalendar",
52+
"prmonth",
53+
"month",
54+
"prcal",
55+
"calendar",
56+
"timegm",
57+
"month_name",
58+
"month_abbr",
59+
"day_name",
60+
"day_abbr",
61+
"Calendar",
62+
"TextCalendar",
63+
"HTMLCalendar",
64+
"LocaleTextCalendar",
65+
"LocaleHTMLCalendar",
66+
"weekheader",
67+
]
3368

3469
_LocaleType = tuple[str | None, str | None]
3570

0 commit comments

Comments
 (0)