Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions mypy/typeshed/stdlib/_compression.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# _compression is replaced by compression._common._streams on Python 3.14+ (PEP-784)

from _typeshed import Incomplete, WriteableBuffer
from _typeshed import ReadableBuffer, WriteableBuffer
from collections.abc import Callable
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
from typing import Any, Protocol, type_check_only
Expand All @@ -13,13 +13,24 @@ class _Reader(Protocol):
def seekable(self) -> bool: ...
def seek(self, n: int, /) -> Any: ...

@type_check_only
class _Decompressor(Protocol):
def decompress(self, data: ReadableBuffer, /, max_length: int = ...) -> bytes: ...
@property
def unused_data(self) -> bytes: ...
@property
def eof(self) -> bool: ...
# `zlib._Decompress` does not have next property, but `DecompressReader` calls it:
# @property
# def needs_input(self) -> bool: ...

class BaseStream(BufferedIOBase): ...

class DecompressReader(RawIOBase):
def __init__(
self,
fp: _Reader,
decomp_factory: Callable[..., Incomplete],
decomp_factory: Callable[..., _Decompressor],
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
**decomp_args: Any, # These are passed to decomp_factory.
) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/protocols.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BaseProtocol:

class Protocol(BaseProtocol):
# Need annotation or mypy will complain about 'Cannot determine type of "__slots__" in base class'
__slots__: tuple[()] = ()
__slots__: tuple[str, ...] = ()
def data_received(self, data: bytes) -> None: ...
def eof_received(self) -> bool | None: ...

Expand All @@ -35,7 +35,7 @@ class DatagramProtocol(BaseProtocol):
def error_received(self, exc: Exception) -> None: ...

class SubprocessProtocol(BaseProtocol):
__slots__: tuple[()] = ()
__slots__: tuple[str, ...] = ()
def pipe_data_received(self, fd: int, data: bytes) -> None: ...
def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ...
def process_exited(self) -> None: ...
23 changes: 12 additions & 11 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ from typing import ( # noqa: Y022,UP035
Any,
BinaryIO,
ClassVar,
Final,
Generic,
Mapping,
MutableMapping,
Expand Down Expand Up @@ -188,8 +189,9 @@ class type:
__bases__: tuple[type, ...]
@property
def __basicsize__(self) -> int: ...
@property
def __dict__(self) -> types.MappingProxyType[str, Any]: ... # type: ignore[override]
# type.__dict__ is read-only at runtime, but that can't be expressed currently.
# See https://github.com/python/typeshed/issues/11033 for a discussion.
__dict__: Final[types.MappingProxyType[str, Any]] # type: ignore[assignment]
@property
def __dictoffset__(self) -> int: ...
@property
Expand Down Expand Up @@ -1267,13 +1269,6 @@ class property:
def __set__(self, instance: Any, value: Any, /) -> None: ...
def __delete__(self, instance: Any, /) -> None: ...

@final
@type_check_only
class _NotImplementedType(Any):
__call__: None

NotImplemented: _NotImplementedType

def abs(x: SupportsAbs[_T], /) -> _T: ...
def all(iterable: Iterable[object], /) -> bool: ...
def any(iterable: Iterable[object], /) -> bool: ...
Expand Down Expand Up @@ -1932,14 +1927,14 @@ def __import__(
def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...

if sys.version_info >= (3, 10):
from types import EllipsisType
from types import EllipsisType, NotImplementedType

# Backwards compatibility hack for folks who relied on the ellipsis type
# existing in typeshed in Python 3.9 and earlier.
ellipsis = EllipsisType

Ellipsis: EllipsisType

NotImplemented: NotImplementedType
else:
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
# not exposed anywhere under that name, we make it private here.
Expand All @@ -1949,6 +1944,12 @@ else:

Ellipsis: ellipsis

@final
@type_check_only
class _NotImplementedType(Any): ...

NotImplemented: _NotImplementedType

@disjoint_base
class BaseException:
args: tuple[Any, ...]
Expand Down
15 changes: 13 additions & 2 deletions mypy/typeshed/stdlib/compression/_common/_streams.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, WriteableBuffer
from _typeshed import ReadableBuffer, WriteableBuffer
from collections.abc import Callable
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
from typing import Any, Protocol, type_check_only
Expand All @@ -11,13 +11,24 @@ class _Reader(Protocol):
def seekable(self) -> bool: ...
def seek(self, n: int, /) -> Any: ...

@type_check_only
class _Decompressor(Protocol):
def decompress(self, data: ReadableBuffer, /, max_length: int = ...) -> bytes: ...
@property
def unused_data(self) -> bytes: ...
@property
def eof(self) -> bool: ...
# `zlib._Decompress` does not have next property, but `DecompressReader` calls it:
# @property
# def needs_input(self) -> bool: ...

class BaseStream(BufferedIOBase): ...

class DecompressReader(RawIOBase):
def __init__(
self,
fp: _Reader,
decomp_factory: Callable[..., Incomplete], # Consider backporting changes to _compression
decomp_factory: Callable[..., _Decompressor], # Consider backporting changes to _compression
trailing_error: type[Exception] | tuple[type[Exception], ...] = (),
**decomp_args: Any, # These are passed to decomp_factory.
) -> None: ...
Expand Down
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/html/parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class HTMLParser(ParserBase):
# Added in Python 3.9.23, 3.10.18, 3.11.13, 3.12.11, 3.13.6
RCDATA_CONTENT_ELEMENTS: Final[tuple[str, ...]]

def __init__(self, *, convert_charrefs: bool = True) -> None: ...
# `scripting` parameter added in Python 3.9.25, 3.10.20, 3.11.15, 3.12.13, 3.13.10, 3.14.1
def __init__(self, *, convert_charrefs: bool = True, scripting: bool = False) -> None: ...
def feed(self, data: str) -> None: ...
def close(self) -> None: ...
def get_starttag_text(self) -> str | None: ...
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/http/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore[misc] # incomp
def begin(self) -> None: ...

class HTTPConnection:
blocksize: int
auto_open: int # undocumented
debuglevel: int
default_port: int # undocumented
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/imaplib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class IMAP4:
class error(Exception): ...
class abort(error): ...
class readonly(abort): ...
utf8_enabled: bool
mustquote: Pattern[str]
debug: int
state: str
Expand Down
16 changes: 15 additions & 1 deletion mypy/typeshed/stdlib/importlib/util.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ from importlib._bootstrap_external import (
spec_from_file_location as spec_from_file_location,
)
from importlib.abc import Loader
from typing_extensions import ParamSpec, deprecated
from types import TracebackType
from typing import Literal
from typing_extensions import ParamSpec, Self, deprecated

_P = ParamSpec("_P")

Expand Down Expand Up @@ -44,6 +46,18 @@ class LazyLoader(Loader):

def source_hash(source_bytes: ReadableBuffer) -> bytes: ...

if sys.version_info >= (3, 12):
class _incompatible_extension_module_restrictions:
def __init__(self, *, disable_check: bool) -> None: ...
disable_check: bool
old: Literal[-1, 0, 1] # exists only while entered
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
@property
def override(self) -> Literal[-1, 1]: ... # undocumented

if sys.version_info >= (3, 14):
__all__ = [
"LazyLoader",
Expand Down
4 changes: 4 additions & 0 deletions mypy/typeshed/stdlib/locale.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ if sys.version_info < (3, 12):
def format_string(f: _str, val: Any, grouping: bool = False, monetary: bool = False) -> _str: ...
def currency(val: float | Decimal, symbol: bool = True, grouping: bool = False, international: bool = False) -> _str: ...
def delocalize(string: _str) -> _str: ...

if sys.version_info >= (3, 10):
def localize(string: _str, grouping: bool = False, monetary: bool = False) -> _str: ...

def atof(string: _str, func: Callable[[_str], float] = ...) -> float: ...
def atoi(string: _str) -> int: ...
def str(val: float) -> _str: ...
Expand Down
27 changes: 14 additions & 13 deletions mypy/typeshed/stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@ from typing import (
runtime_checkable,
type_check_only,
)
from typing_extensions import Self, TypeAlias, Unpack, deprecated
from typing_extensions import LiteralString, Self, TypeAlias, Unpack, deprecated

from . import path as _path

# Re-export common definitions from os.path to reduce duplication
from .path import (
altsep as altsep,
curdir as curdir,
defpath as defpath,
devnull as devnull,
extsep as extsep,
pardir as pardir,
pathsep as pathsep,
sep as sep,
)

__all__ = [
"F_OK",
"O_APPEND",
Expand Down Expand Up @@ -674,19 +686,8 @@ if sys.platform != "win32":
ST_NOSUID: Final[int]
ST_RDONLY: Final[int]

curdir: str
pardir: str
sep: str
if sys.platform == "win32":
altsep: str
else:
altsep: str | None
extsep: str
pathsep: str
defpath: str
linesep: Literal["\n", "\r\n"]
devnull: str
name: str
name: LiteralString

F_OK: Final = 0
R_OK: Final = 4
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def expr(source: str) -> STType: ...
def suite(source: str) -> STType: ...
def sequence2st(sequence: Sequence[Any]) -> STType: ...
def tuple2st(sequence: Sequence[Any]) -> STType: ...
def st2list(st: STType, line_info: bool = ..., col_info: bool = ...) -> list[Any]: ...
def st2tuple(st: STType, line_info: bool = ..., col_info: bool = ...) -> tuple[Any, ...]: ...
def st2list(st: STType, line_info: bool = False, col_info: bool = False) -> list[Any]: ...
def st2tuple(st: STType, line_info: bool = False, col_info: bool = False) -> tuple[Any, ...]: ...
def compilest(st: STType, filename: StrOrBytesPath = ...) -> CodeType: ...
def isexpr(st: STType) -> bool: ...
def issuite(st: STType) -> bool: ...
Expand All @@ -21,5 +21,5 @@ class STType:
def compile(self, filename: StrOrBytesPath = ...) -> CodeType: ...
def isexpr(self) -> bool: ...
def issuite(self) -> bool: ...
def tolist(self, line_info: bool = ..., col_info: bool = ...) -> list[Any]: ...
def totuple(self, line_info: bool = ..., col_info: bool = ...) -> tuple[Any, ...]: ...
def tolist(self, line_info: bool = False, col_info: bool = False) -> list[Any]: ...
def totuple(self, line_info: bool = False, col_info: bool = False) -> tuple[Any, ...]: ...
12 changes: 8 additions & 4 deletions mypy/typeshed/stdlib/select.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import sys
from _typeshed import FileDescriptorLike
from collections.abc import Iterable
from types import TracebackType
from typing import Any, ClassVar, Final, final
from typing_extensions import Self
from typing import Any, ClassVar, Final, TypeVar, final
from typing_extensions import Never, Self

if sys.platform != "win32":
PIPE_BUF: Final[int]
Expand Down Expand Up @@ -31,9 +31,13 @@ if sys.platform != "win32":
def unregister(self, fd: FileDescriptorLike, /) -> None: ...
def poll(self, timeout: float | None = None, /) -> list[tuple[int, int]]: ...

_R = TypeVar("_R", default=Never)
_W = TypeVar("_W", default=Never)
_X = TypeVar("_X", default=Never)

def select(
rlist: Iterable[Any], wlist: Iterable[Any], xlist: Iterable[Any], timeout: float | None = None, /
) -> tuple[list[Any], list[Any], list[Any]]: ...
rlist: Iterable[_R], wlist: Iterable[_W], xlist: Iterable[_X], timeout: float | None = None, /
) -> tuple[list[_R], list[_W], list[_X]]: ...

error = OSError

Expand Down
3 changes: 3 additions & 0 deletions mypy/typeshed/stdlib/ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ from typing_extensions import Never, Self, TypeAlias, deprecated
if sys.version_info >= (3, 13):
from _ssl import HAS_PSK as HAS_PSK

if sys.version_info >= (3, 14):
from _ssl import HAS_PHA as HAS_PHA

if sys.version_info < (3, 12):
from _ssl import RAND_pseudo_bytes as RAND_pseudo_bytes

Expand Down
Loading