Skip to content

Sync typeshed #19440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
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
21 changes: 15 additions & 6 deletions mypy/typeshed/stdlib/_interpreters.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import types
from collections.abc import Callable, Mapping
from typing import Final, Literal, SupportsIndex
from collections.abc import Callable
from typing import Any, Final, Literal, SupportsIndex
from typing_extensions import TypeAlias

_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""]
_SharedDict: TypeAlias = dict[str, Any] # many objects can be shared

class InterpreterError(Exception): ...
class InterpreterNotFoundError(InterpreterError): ...
Expand All @@ -22,7 +23,11 @@ def is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ...
def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ...
def whence(id: SupportsIndex) -> int: ...
def exec(
id: SupportsIndex, code: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
id: SupportsIndex,
code: str | types.CodeType | Callable[[], object],
shared: _SharedDict | None = None,
*,
restrict: bool = False,
) -> None | types.SimpleNamespace: ...
def call(
id: SupportsIndex,
Expand All @@ -33,12 +38,16 @@ def call(
restrict: bool = False,
) -> object: ...
def run_string(
id: SupportsIndex, script: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
id: SupportsIndex,
script: str | types.CodeType | Callable[[], object],
shared: _SharedDict | None = None,
*,
restrict: bool = False,
) -> None: ...
def run_func(
id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: _SharedDict | None = None, *, restrict: bool = False
) -> None: ...
def set___main___attrs(id: SupportsIndex, updates: Mapping[str, object], *, restrict: bool = False) -> None: ...
def set___main___attrs(id: SupportsIndex, updates: _SharedDict, *, restrict: bool = False) -> None: ...
def incref(id: SupportsIndex, *, implieslink: bool = False, restrict: bool = False) -> None: ...
def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ...
def is_shareable(obj: object) -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class make_encoder:
@property
def key_separator(self) -> str: ...
@property
def indent(self) -> int | None: ...
def indent(self) -> str | None: ...
@property
def markers(self) -> dict[int, Any] | None: ...
@property
Expand All @@ -25,7 +25,7 @@ class make_encoder:
markers: dict[int, Any] | None,
default: Callable[[Any], Any],
encoder: Callable[[str], str],
indent: int | None,
indent: str | None,
key_separator: str,
item_separator: str,
sort_keys: bool,
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_markupbase.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class ParserBase:
def reset(self) -> None: ...
def getpos(self) -> tuple[int, int]: ...
def unknown_decl(self, data: str) -> None: ...
def parse_comment(self, i: int, report: int = 1) -> int: ... # undocumented
def parse_comment(self, i: int, report: bool = True) -> int: ... # undocumented
def parse_declaration(self, i: int) -> int: ... # undocumented
def parse_marked_section(self, i: int, report: int = 1) -> int: ... # undocumented
def parse_marked_section(self, i: int, report: bool = True) -> int: ... # undocumented
def updatepos(self, i: int, j: int) -> int: ... # undocumented
if sys.version_info < (3, 10):
# Removed from ParserBase: https://bugs.python.org/issue31844
Expand Down
38 changes: 22 additions & 16 deletions mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,16 @@ class Constant(expr):
kind: str | None
if sys.version_info < (3, 14):
# Aliases for value, for backwards compatibility
s: _ConstantValue
n: _ConstantValue
@deprecated("Will be removed in Python 3.14; use value instead")
@property
def n(self) -> _ConstantValue: ...
@n.setter
def n(self, value: _ConstantValue) -> None: ...
@deprecated("Will be removed in Python 3.14; use value instead")
@property
def s(self) -> _ConstantValue: ...
@s.setter
def s(self, value: _ConstantValue) -> None: ...

def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...

Expand Down Expand Up @@ -1495,11 +1503,11 @@ if sys.version_info >= (3, 10):

class MatchSingleton(pattern):
__match_args__ = ("value",)
value: Literal[True, False] | None
def __init__(self, value: Literal[True, False] | None, **kwargs: Unpack[_Attributes[int]]) -> None: ...
value: bool | None
def __init__(self, value: bool | None, **kwargs: Unpack[_Attributes[int]]) -> None: ...

if sys.version_info >= (3, 14):
def __replace__(self, *, value: Literal[True, False] | None = ..., **kwargs: Unpack[_Attributes[int]]) -> Self: ...
def __replace__(self, *, value: bool | None = ..., **kwargs: Unpack[_Attributes[int]]) -> Self: ...

class MatchSequence(pattern):
__match_args__ = ("patterns",)
Expand Down Expand Up @@ -1696,25 +1704,23 @@ class _ABC(type):
if sys.version_info < (3, 14):
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Num(Constant, metaclass=_ABC):
value: int | float | complex
def __new__(cls, n: complex, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]

@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Str(Constant, metaclass=_ABC):
value: str
# Aliases for value, for backwards compatibility
s: str
def __new__(cls, s: str, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]

@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Bytes(Constant, metaclass=_ABC):
value: bytes
# Aliases for value, for backwards compatibility
s: bytes
def __new__(cls, s: bytes, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]

@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class NameConstant(Constant, metaclass=_ABC): ...
class NameConstant(Constant, metaclass=_ABC):
def __new__(cls, value: _ConstantValue, kind: str | None, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]

@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Ellipsis(Constant, metaclass=_ABC): ...
class Ellipsis(Constant, metaclass=_ABC):
def __new__(cls, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor]

# everything below here is defined in ast.py

Expand Down Expand Up @@ -1797,7 +1803,7 @@ if sys.version_info >= (3, 13):
type_comments: bool = False,
feature_version: None | int | tuple[int, int] = None,
optimize: Literal[-1, 0, 1, 2] = -1,
) -> AST: ...
) -> mod: ...

else:
@overload
Expand Down Expand Up @@ -1868,7 +1874,7 @@ else:
*,
type_comments: bool = False,
feature_version: None | int | tuple[int, int] = None,
) -> AST: ...
) -> mod: ...

def literal_eval(node_or_string: str | AST) -> Any: ...

Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/asyncio/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ruff: noqa: PLR5501 # This condition is so big, it's clearer to keep to platform condition in two blocks
# This condition is so big, it's clearer to keep to platform condition in two blocks
# Can't NOQA on a specific line: https://github.com/plinss/flake8-noqa/issues/22
import sys
from collections.abc import Awaitable, Coroutine, Generator
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class bytes(Sequence[int]):
def strip(self, bytes: ReadableBuffer | None = None, /) -> bytes: ...
def swapcase(self) -> bytes: ...
def title(self) -> bytes: ...
def translate(self, table: ReadableBuffer | None, /, delete: bytes = b"") -> bytes: ...
def translate(self, table: ReadableBuffer | None, /, delete: ReadableBuffer = b"") -> bytes: ...
def upper(self) -> bytes: ...
def zfill(self, width: SupportsIndex, /) -> bytes: ...
@classmethod
Expand Down
4 changes: 4 additions & 0 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class UserDict(MutableMapping[_KT, _VT]):
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _VT) -> _VT: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...

class UserList(MutableSequence[_T]):
Expand Down Expand Up @@ -452,6 +454,8 @@ class ChainMap(MutableMapping[_KT, _VT]):
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _VT) -> _VT: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...
def __missing__(self, key: _KT) -> _VT: ... # undocumented
def __bool__(self) -> bool: ...
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/compression/zstd/_zstdfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from collections.abc import Mapping
from compression._common import _streams
from compression.zstd import ZstdDict
from io import TextIOWrapper, _WrappedBuffer
from typing import Literal, overload, type_check_only
from typing import Literal, Protocol, overload, type_check_only
from typing_extensions import TypeAlias

from _zstd import ZstdCompressor, _ZstdCompressorFlushBlock, _ZstdCompressorFlushFrame
Expand All @@ -16,11 +16,11 @@ _ReadTextMode: TypeAlias = Literal["rt"]
_WriteTextMode: TypeAlias = Literal["wt", "xt", "at"]

@type_check_only
class _FileBinaryRead(_streams._Reader):
class _FileBinaryRead(_streams._Reader, Protocol):
def close(self) -> None: ...

@type_check_only
class _FileBinaryWrite(SupportsWrite[bytes]):
class _FileBinaryWrite(SupportsWrite[bytes], Protocol):
def close(self) -> None: ...

class ZstdFile(_streams.BaseStream):
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if sys.platform == "win32":
from _ctypes import FormatError as FormatError, get_last_error as get_last_error, set_last_error as set_last_error

if sys.version_info >= (3, 14):
from _ctypes import COMError as COMError
from _ctypes import COMError as COMError, CopyComPointer as CopyComPointer

if sys.version_info >= (3, 11):
from ctypes._endian import BigEndianUnion as BigEndianUnion, LittleEndianUnion as LittleEndianUnion
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/html/parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HTMLParser(ParserBase):
def check_for_whole_start_tag(self, i: int) -> int: ... # undocumented
def clear_cdata_mode(self) -> None: ... # undocumented
def goahead(self, end: bool) -> None: ... # undocumented
def parse_bogus_comment(self, i: int, report: bool = ...) -> int: ... # undocumented
def parse_bogus_comment(self, i: int, report: bool = True) -> int: ... # undocumented
def parse_endtag(self, i: int) -> int: ... # undocumented
def parse_html_declaration(self, i: int) -> int: ... # undocumented
def parse_pi(self, i: int) -> int: ... # undocumented
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/importlib/metadata/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ if sys.version_info >= (3, 10) and sys.version_info < (3, 12):
@overload
def get(self, name: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, name: _KT, default: _VT) -> _VT: ...
@overload
def get(self, name: _KT, default: _T) -> _VT | _T: ...
def __iter__(self) -> Iterator[_KT]: ...
def __contains__(self, *args: object) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/string/templatelib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class Interpolation:
__match_args__ = ("value", "expression", "conversion", "format_spec")

def __new__(
cls, value: Any, expression: str, conversion: Literal["a", "r", "s"] | None = None, format_spec: str = ""
cls, value: Any, expression: str = "", conversion: Literal["a", "r", "s"] | None = None, format_spec: str = ""
) -> Interpolation: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4 changes: 4 additions & 0 deletions mypy/typeshed/stdlib/sys/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ else:

def _current_frames() -> dict[int, FrameType]: ...
def _getframe(depth: int = 0, /) -> FrameType: ...

if sys.version_info >= (3, 12):
def _getframemodulename(depth: int = 0) -> str | None: ...

def _debugmallocstats() -> None: ...
def __displayhook__(object: object, /) -> None: ...
def __excepthook__(exctype: type[BaseException], value: BaseException, traceback: TracebackType | None, /) -> None: ...
Expand Down
Loading
Loading