Skip to content

Commit

Permalink
Sync typeshed (#12596)
Browse files Browse the repository at this point in the history
Source commit:
python/typeshed@d09689f

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja authored and JukkaL committed Apr 19, 2022
1 parent d96330b commit c4a9697
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 133 deletions.
82 changes: 82 additions & 0 deletions mypy/typeshed/stdlib/_pydecimal.pyi
@@ -1,3 +1,85 @@
import sys

# This is a slight lie, the implementations aren't exactly identical
# However, in all likelihood, the differences are inconsequential
from decimal import *

if sys.version_info >= (3, 7):
__all__ = [
"Decimal",
"Context",
"DecimalTuple",
"DefaultContext",
"BasicContext",
"ExtendedContext",
"DecimalException",
"Clamped",
"InvalidOperation",
"DivisionByZero",
"Inexact",
"Rounded",
"Subnormal",
"Overflow",
"Underflow",
"FloatOperation",
"DivisionImpossible",
"InvalidContext",
"ConversionSyntax",
"DivisionUndefined",
"ROUND_DOWN",
"ROUND_HALF_UP",
"ROUND_HALF_EVEN",
"ROUND_CEILING",
"ROUND_FLOOR",
"ROUND_UP",
"ROUND_HALF_DOWN",
"ROUND_05UP",
"setcontext",
"getcontext",
"localcontext",
"MAX_PREC",
"MAX_EMAX",
"MIN_EMIN",
"MIN_ETINY",
"HAVE_THREADS",
"HAVE_CONTEXTVAR",
]
else:
__all__ = [
"Decimal",
"Context",
"DecimalTuple",
"DefaultContext",
"BasicContext",
"ExtendedContext",
"DecimalException",
"Clamped",
"InvalidOperation",
"DivisionByZero",
"Inexact",
"Rounded",
"Subnormal",
"Overflow",
"Underflow",
"FloatOperation",
"DivisionImpossible",
"InvalidContext",
"ConversionSyntax",
"DivisionUndefined",
"ROUND_DOWN",
"ROUND_HALF_UP",
"ROUND_HALF_EVEN",
"ROUND_CEILING",
"ROUND_FLOOR",
"ROUND_UP",
"ROUND_HALF_DOWN",
"ROUND_05UP",
"setcontext",
"getcontext",
"localcontext",
"MAX_PREC",
"MAX_EMAX",
"MIN_EMIN",
"MIN_ETINY",
"HAVE_THREADS",
]
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/streams.pyi
Expand Up @@ -159,13 +159,13 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
class StreamWriter:
def __init__(
self,
transport: transports.BaseTransport,
transport: transports.WriteTransport,
protocol: protocols.BaseProtocol,
reader: StreamReader | None,
loop: events.AbstractEventLoop,
) -> None: ...
@property
def transport(self) -> transports.BaseTransport: ...
def transport(self) -> transports.WriteTransport: ...
def write(self, data: bytes) -> None: ...
def writelines(self, data: Iterable[bytes]) -> None: ...
def write_eof(self) -> None: ...
Expand Down
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/asyncio/transports.pyi
Expand Up @@ -27,6 +27,9 @@ class ReadTransport(BaseTransport):
class WriteTransport(BaseTransport):
def set_write_buffer_limits(self, high: int | None = ..., low: int | None = ...) -> None: ...
def get_write_buffer_size(self) -> int: ...
if sys.version_info >= (3, 9):
def get_write_buffer_limits(self) -> tuple[int, int]: ...

def write(self, data: Any) -> None: ...
def writelines(self, list_of_data: list[Any]) -> None: ...
def write_eof(self) -> None: ...
Expand Down
41 changes: 21 additions & 20 deletions mypy/typeshed/stdlib/base64.pyi
@@ -1,4 +1,5 @@
import sys
from _typeshed import ReadableBuffer
from typing import IO

if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -46,30 +47,30 @@ else:
"urlsafe_b64decode",
]

def b64encode(s: bytes, altchars: bytes | None = ...) -> bytes: ...
def b64decode(s: str | bytes, altchars: bytes | None = ..., validate: bool = ...) -> bytes: ...
def standard_b64encode(s: bytes) -> bytes: ...
def standard_b64decode(s: str | bytes) -> bytes: ...
def urlsafe_b64encode(s: bytes) -> bytes: ...
def urlsafe_b64decode(s: str | bytes) -> bytes: ...
def b32encode(s: bytes) -> bytes: ...
def b32decode(s: str | bytes, casefold: bool = ..., map01: bytes | None = ...) -> bytes: ...
def b16encode(s: bytes) -> bytes: ...
def b16decode(s: str | bytes, casefold: bool = ...) -> bytes: ...
def b64encode(s: ReadableBuffer, altchars: ReadableBuffer | None = ...) -> bytes: ...
def b64decode(s: str | ReadableBuffer, altchars: ReadableBuffer | None = ..., validate: bool = ...) -> bytes: ...
def standard_b64encode(s: ReadableBuffer) -> bytes: ...
def standard_b64decode(s: str | ReadableBuffer) -> bytes: ...
def urlsafe_b64encode(s: ReadableBuffer) -> bytes: ...
def urlsafe_b64decode(s: str | ReadableBuffer) -> bytes: ...
def b32encode(s: ReadableBuffer) -> bytes: ...
def b32decode(s: str | ReadableBuffer, casefold: bool = ..., map01: bytes | None = ...) -> bytes: ...
def b16encode(s: ReadableBuffer) -> bytes: ...
def b16decode(s: str | ReadableBuffer, casefold: bool = ...) -> bytes: ...

if sys.version_info >= (3, 10):
def b32hexencode(s: bytes) -> bytes: ...
def b32hexdecode(s: str | bytes, casefold: bool = ...) -> bytes: ...
def b32hexencode(s: ReadableBuffer) -> bytes: ...
def b32hexdecode(s: str | ReadableBuffer, casefold: bool = ...) -> bytes: ...

def a85encode(b: bytes, *, foldspaces: bool = ..., wrapcol: int = ..., pad: bool = ..., adobe: bool = ...) -> bytes: ...
def a85decode(b: str | bytes, *, foldspaces: bool = ..., adobe: bool = ..., ignorechars: str | bytes = ...) -> bytes: ...
def b85encode(b: bytes, pad: bool = ...) -> bytes: ...
def b85decode(b: str | bytes) -> bytes: ...
def a85encode(b: ReadableBuffer, *, foldspaces: bool = ..., wrapcol: int = ..., pad: bool = ..., adobe: bool = ...) -> bytes: ...
def a85decode(b: str | ReadableBuffer, *, foldspaces: bool = ..., adobe: bool = ..., ignorechars: str | bytes = ...) -> bytes: ...
def b85encode(b: ReadableBuffer, pad: bool = ...) -> bytes: ...
def b85decode(b: str | ReadableBuffer) -> bytes: ...
def decode(input: IO[bytes], output: IO[bytes]) -> None: ...
def encode(input: IO[bytes], output: IO[bytes]) -> None: ...
def encodebytes(s: bytes) -> bytes: ...
def decodebytes(s: bytes) -> bytes: ...
def encodebytes(s: ReadableBuffer) -> bytes: ...
def decodebytes(s: ReadableBuffer) -> bytes: ...

if sys.version_info < (3, 9):
def encodestring(s: bytes) -> bytes: ...
def decodestring(s: bytes) -> bytes: ...
def encodestring(s: ReadableBuffer) -> bytes: ...
def decodestring(s: ReadableBuffer) -> bytes: ...
47 changes: 36 additions & 11 deletions mypy/typeshed/stdlib/builtins.pyi
Expand Up @@ -52,7 +52,6 @@ from typing import (
SupportsInt,
SupportsRound,
TypeVar,
Union,
overload,
)
from typing_extensions import Literal, SupportsIndex, TypeGuard, final
Expand Down Expand Up @@ -1747,19 +1746,45 @@ if sys.version_info >= (3, 10):
class EncodingWarning(Warning): ...

if sys.version_info >= (3, 11):
_SplitCondition = Union[type[BaseException], tuple[type[BaseException], ...], Callable[[BaseException], bool]]
_BaseExceptionT_co = TypeVar("_BaseExceptionT_co", bound=BaseException, covariant=True)
_BaseExceptionT = TypeVar("_BaseExceptionT", bound=BaseException)
_ExceptionT_co = TypeVar("_ExceptionT_co", bound=Exception, covariant=True)
_ExceptionT = TypeVar("_ExceptionT", bound=Exception)

class BaseExceptionGroup(BaseException):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[BaseException]) -> Self: ...
class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ...
@property
def message(self) -> str: ...
@property
def exceptions(self) -> tuple[BaseException, ...]: ...
def subgroup(self: Self, __condition: _SplitCondition) -> Self | None: ...
def split(self: Self, __condition: _SplitCondition) -> tuple[Self | None, Self | None]: ...
def derive(self: Self, __excs: Sequence[BaseException]) -> Self: ...
def exceptions(self) -> tuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]: ...
@overload
def subgroup(
self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
) -> BaseExceptionGroup[_BaseExceptionT] | None: ...
@overload
def subgroup(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> Self | None: ...
@overload
def split(
self: Self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]: ...
@overload
def split(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> tuple[Self | None, Self | None]: ...
def derive(self: Self, __excs: Sequence[_BaseExceptionT_co]) -> Self: ...

class ExceptionGroup(BaseExceptionGroup, Exception):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[Exception]) -> Self: ...
class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ...
@property
def exceptions(self) -> tuple[Exception, ...]: ...
def exceptions(self) -> tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]: ...
# We accept a narrower type, but that's OK.
@overload # type: ignore[override]
def subgroup(
self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
) -> ExceptionGroup[_ExceptionT] | None: ...
@overload
def subgroup(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> Self | None: ...
@overload # type: ignore[override]
def split(
self: Self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
) -> tuple[ExceptionGroup[_ExceptionT] | None, Self | None]: ...
@overload
def split(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> tuple[Self | None, Self | None]: ...
87 changes: 61 additions & 26 deletions mypy/typeshed/stdlib/calendar.pyi
Expand Up @@ -4,32 +4,67 @@ from collections.abc import Iterable, Sequence
from time import struct_time
from typing_extensions import Literal

__all__ = [
"IllegalMonthError",
"IllegalWeekdayError",
"setfirstweekday",
"firstweekday",
"isleap",
"leapdays",
"weekday",
"monthrange",
"monthcalendar",
"prmonth",
"month",
"prcal",
"calendar",
"timegm",
"month_name",
"month_abbr",
"day_name",
"day_abbr",
"Calendar",
"TextCalendar",
"HTMLCalendar",
"LocaleTextCalendar",
"LocaleHTMLCalendar",
"weekheader",
]
if sys.version_info >= (3, 10):
__all__ = [
"IllegalMonthError",
"IllegalWeekdayError",
"setfirstweekday",
"firstweekday",
"isleap",
"leapdays",
"weekday",
"monthrange",
"monthcalendar",
"prmonth",
"month",
"prcal",
"calendar",
"timegm",
"month_name",
"month_abbr",
"day_name",
"day_abbr",
"Calendar",
"TextCalendar",
"HTMLCalendar",
"LocaleTextCalendar",
"LocaleHTMLCalendar",
"weekheader",
"FRIDAY",
"MONDAY",
"SATURDAY",
"SUNDAY",
"THURSDAY",
"TUESDAY",
"WEDNESDAY",
]
else:
__all__ = [
"IllegalMonthError",
"IllegalWeekdayError",
"setfirstweekday",
"firstweekday",
"isleap",
"leapdays",
"weekday",
"monthrange",
"monthcalendar",
"prmonth",
"month",
"prcal",
"calendar",
"timegm",
"month_name",
"month_abbr",
"day_name",
"day_abbr",
"Calendar",
"TextCalendar",
"HTMLCalendar",
"LocaleTextCalendar",
"LocaleHTMLCalendar",
"weekheader",
]

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

Expand Down

0 comments on commit c4a9697

Please sign in to comment.