Skip to content

Commit b546953

Browse files
authored
Sync typeshed (#19446)
Source commit: python/typeshed@84e41f2
1 parent 6403752 commit b546953

File tree

23 files changed

+193
-42
lines changed

23 files changed

+193
-42
lines changed

mypy/typeshed/stdlib/_interpreters.pyi

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import types
2-
from collections.abc import Callable, Mapping
3-
from typing import Final, Literal, SupportsIndex
2+
from collections.abc import Callable
3+
from typing import Any, Final, Literal, SupportsIndex
44
from typing_extensions import TypeAlias
55

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

89
class InterpreterError(Exception): ...
910
class InterpreterNotFoundError(InterpreterError): ...
@@ -22,7 +23,11 @@ def is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ...
2223
def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ...
2324
def whence(id: SupportsIndex) -> int: ...
2425
def exec(
25-
id: SupportsIndex, code: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
26+
id: SupportsIndex,
27+
code: str | types.CodeType | Callable[[], object],
28+
shared: _SharedDict | None = None,
29+
*,
30+
restrict: bool = False,
2631
) -> None | types.SimpleNamespace: ...
2732
def call(
2833
id: SupportsIndex,
@@ -33,12 +38,16 @@ def call(
3338
restrict: bool = False,
3439
) -> object: ...
3540
def run_string(
36-
id: SupportsIndex, script: str | types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
41+
id: SupportsIndex,
42+
script: str | types.CodeType | Callable[[], object],
43+
shared: _SharedDict | None = None,
44+
*,
45+
restrict: bool = False,
3746
) -> None: ...
3847
def run_func(
39-
id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: bool | None = None, *, restrict: bool = False
48+
id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: _SharedDict | None = None, *, restrict: bool = False
4049
) -> None: ...
41-
def set___main___attrs(id: SupportsIndex, updates: Mapping[str, object], *, restrict: bool = False) -> None: ...
50+
def set___main___attrs(id: SupportsIndex, updates: _SharedDict, *, restrict: bool = False) -> None: ...
4251
def incref(id: SupportsIndex, *, implieslink: bool = False, restrict: bool = False) -> None: ...
4352
def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ...
4453
def is_shareable(obj: object) -> bool: ...

mypy/typeshed/stdlib/_json.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class make_encoder:
1111
@property
1212
def key_separator(self) -> str: ...
1313
@property
14-
def indent(self) -> int | None: ...
14+
def indent(self) -> str | None: ...
1515
@property
1616
def markers(self) -> dict[int, Any] | None: ...
1717
@property
@@ -25,7 +25,7 @@ class make_encoder:
2525
markers: dict[int, Any] | None,
2626
default: Callable[[Any], Any],
2727
encoder: Callable[[str], str],
28-
indent: int | None,
28+
indent: str | None,
2929
key_separator: str,
3030
item_separator: str,
3131
sort_keys: bool,

mypy/typeshed/stdlib/_markupbase.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ class ParserBase:
55
def reset(self) -> None: ...
66
def getpos(self) -> tuple[int, int]: ...
77
def unknown_decl(self, data: str) -> None: ...
8-
def parse_comment(self, i: int, report: int = 1) -> int: ... # undocumented
8+
def parse_comment(self, i: int, report: bool = True) -> int: ... # undocumented
99
def parse_declaration(self, i: int) -> int: ... # undocumented
10-
def parse_marked_section(self, i: int, report: int = 1) -> int: ... # undocumented
10+
def parse_marked_section(self, i: int, report: bool = True) -> int: ... # undocumented
1111
def updatepos(self, i: int, j: int) -> int: ... # undocumented
1212
if sys.version_info < (3, 10):
1313
# Removed from ParserBase: https://bugs.python.org/issue31844

mypy/typeshed/stdlib/ast.pyi

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,16 @@ class Constant(expr):
10961096
kind: str | None
10971097
if sys.version_info < (3, 14):
10981098
# Aliases for value, for backwards compatibility
1099-
s: _ConstantValue
1100-
n: _ConstantValue
1099+
@deprecated("Will be removed in Python 3.14; use value instead")
1100+
@property
1101+
def n(self) -> _ConstantValue: ...
1102+
@n.setter
1103+
def n(self, value: _ConstantValue) -> None: ...
1104+
@deprecated("Will be removed in Python 3.14; use value instead")
1105+
@property
1106+
def s(self) -> _ConstantValue: ...
1107+
@s.setter
1108+
def s(self, value: _ConstantValue) -> None: ...
11011109

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

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

14961504
class MatchSingleton(pattern):
14971505
__match_args__ = ("value",)
1498-
value: Literal[True, False] | None
1499-
def __init__(self, value: Literal[True, False] | None, **kwargs: Unpack[_Attributes[int]]) -> None: ...
1506+
value: bool | None
1507+
def __init__(self, value: bool | None, **kwargs: Unpack[_Attributes[int]]) -> None: ...
15001508

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

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

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

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

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

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

17191725
# everything below here is defined in ast.py
17201726

@@ -1797,7 +1803,7 @@ if sys.version_info >= (3, 13):
17971803
type_comments: bool = False,
17981804
feature_version: None | int | tuple[int, int] = None,
17991805
optimize: Literal[-1, 0, 1, 2] = -1,
1800-
) -> AST: ...
1806+
) -> mod: ...
18011807

18021808
else:
18031809
@overload
@@ -1868,7 +1874,7 @@ else:
18681874
*,
18691875
type_comments: bool = False,
18701876
feature_version: None | int | tuple[int, int] = None,
1871-
) -> AST: ...
1877+
) -> mod: ...
18721878

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

mypy/typeshed/stdlib/asyncio/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ruff: noqa: PLR5501 # This condition is so big, it's clearer to keep to platform condition in two blocks
1+
# This condition is so big, it's clearer to keep to platform condition in two blocks
22
# Can't NOQA on a specific line: https://github.com/plinss/flake8-noqa/issues/22
33
import sys
44
from collections.abc import Awaitable, Coroutine, Generator

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class bytes(Sequence[int]):
609609
def strip(self, bytes: ReadableBuffer | None = None, /) -> bytes: ...
610610
def swapcase(self) -> bytes: ...
611611
def title(self) -> bytes: ...
612-
def translate(self, table: ReadableBuffer | None, /, delete: bytes = b"") -> bytes: ...
612+
def translate(self, table: ReadableBuffer | None, /, delete: ReadableBuffer = b"") -> bytes: ...
613613
def upper(self) -> bytes: ...
614614
def zfill(self, width: SupportsIndex, /) -> bytes: ...
615615
@classmethod

mypy/typeshed/stdlib/collections/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class UserDict(MutableMapping[_KT, _VT]):
108108
@overload
109109
def get(self, key: _KT, default: None = None) -> _VT | None: ...
110110
@overload
111+
def get(self, key: _KT, default: _VT) -> _VT: ...
112+
@overload
111113
def get(self, key: _KT, default: _T) -> _VT | _T: ...
112114

113115
class UserList(MutableSequence[_T]):
@@ -452,6 +454,8 @@ class ChainMap(MutableMapping[_KT, _VT]):
452454
@overload
453455
def get(self, key: _KT, default: None = None) -> _VT | None: ...
454456
@overload
457+
def get(self, key: _KT, default: _VT) -> _VT: ...
458+
@overload
455459
def get(self, key: _KT, default: _T) -> _VT | _T: ...
456460
def __missing__(self, key: _KT) -> _VT: ... # undocumented
457461
def __bool__(self) -> bool: ...

0 commit comments

Comments
 (0)