Skip to content

Commit 206f5ca

Browse files
committed
Add Python 3.15 JSON updates
1 parent f74b24b commit 206f5ca

4 files changed

Lines changed: 89 additions & 38 deletions

File tree

stdlib/@tests/stubtest_allowlists/py315.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ _frozen_importlib_external._LoaderBasics.load_module
1414
_frozen_importlib_external.cache_from_source
1515
_interpqueues.create
1616
_interpqueues.put
17-
_json.make_scanner.array_hook
18-
_json.scanstring
1917
_pyrepl.base_eventqueue
2018
_pyrepl.commands
2119
_pyrepl.completing_reader
@@ -182,9 +180,6 @@ io.Reader.__class_getitem__
182180
io.Reader.read
183181
io.Writer.__class_getitem__
184182
io.Writer.write
185-
json.decoder.JSONDecoder.__init__
186-
json.load
187-
json.loads
188183
mailbox.Mailbox.__enter__
189184
mailbox.Mailbox.__exit__
190185
mailbox._ProxyFile.__class_getitem__

stdlib/_json.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from collections.abc import Callable
23
from typing import Any, final
34
from typing_extensions import Self
@@ -36,6 +37,8 @@ class make_encoder:
3637

3738
@final
3839
class make_scanner:
40+
if sys.version_info >= (3, 15):
41+
array_hook: Any
3942
object_hook: Any
4043
object_pairs_hook: Any
4144
parse_int: Any
@@ -48,4 +51,9 @@ class make_scanner:
4851

4952
def encode_basestring(s: str, /) -> str: ...
5053
def encode_basestring_ascii(s: str, /) -> str: ...
51-
def scanstring(string: str, end: int, strict: bool = True) -> tuple[str, int]: ...
54+
55+
if sys.version_info >= (3, 15):
56+
def scanstring(pystr: str, end: int, strict: bool = True, /) -> tuple[str, int]: ...
57+
58+
else:
59+
def scanstring(string: str, end: int, strict: bool = True) -> tuple[str, int]: ...

stdlib/json/__init__.pyi

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from _typeshed import SupportsRead, SupportsWrite
23
from collections.abc import Callable
34
from typing import Any, Literal
@@ -36,28 +37,57 @@ def dump(
3637
sort_keys: bool = False,
3738
**kwds: Any,
3839
) -> None: ...
39-
def loads(
40-
s: str | bytes | bytearray,
41-
*,
42-
cls: type[JSONDecoder] | None = None,
43-
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
44-
parse_float: Callable[[str], Any] | None = None,
45-
parse_int: Callable[[str], Any] | None = None,
46-
parse_constant: Callable[[str], Any] | None = None,
47-
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None,
48-
**kwds: Any,
49-
) -> Any: ...
50-
def load(
51-
fp: SupportsRead[str | bytes],
52-
*,
53-
cls: type[JSONDecoder] | None = None,
54-
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
55-
parse_float: Callable[[str], Any] | None = None,
56-
parse_int: Callable[[str], Any] | None = None,
57-
parse_constant: Callable[[str], Any] | None = None,
58-
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None,
59-
**kwds: Any,
60-
) -> Any: ...
40+
41+
if sys.version_info >= (3, 15):
42+
def loads(
43+
s: str | bytes | bytearray,
44+
*,
45+
cls: type[JSONDecoder] | None = None,
46+
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
47+
parse_float: Callable[[str], Any] | None = None,
48+
parse_int: Callable[[str], Any] | None = None,
49+
parse_constant: Callable[[str], Any] | None = None,
50+
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None,
51+
array_hook: Callable[[list[Any]], Any] | None = None,
52+
**kwds: Any,
53+
) -> Any: ...
54+
def load(
55+
fp: SupportsRead[str | bytes],
56+
*,
57+
cls: type[JSONDecoder] | None = None,
58+
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
59+
parse_float: Callable[[str], Any] | None = None,
60+
parse_int: Callable[[str], Any] | None = None,
61+
parse_constant: Callable[[str], Any] | None = None,
62+
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None,
63+
array_hook: Callable[[list[Any]], Any] | None = None,
64+
**kwds: Any,
65+
) -> Any: ...
66+
67+
else:
68+
def loads(
69+
s: str | bytes | bytearray,
70+
*,
71+
cls: type[JSONDecoder] | None = None,
72+
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
73+
parse_float: Callable[[str], Any] | None = None,
74+
parse_int: Callable[[str], Any] | None = None,
75+
parse_constant: Callable[[str], Any] | None = None,
76+
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None,
77+
**kwds: Any,
78+
) -> Any: ...
79+
def load(
80+
fp: SupportsRead[str | bytes],
81+
*,
82+
cls: type[JSONDecoder] | None = None,
83+
object_hook: Callable[[dict[Any, Any]], Any] | None = None,
84+
parse_float: Callable[[str], Any] | None = None,
85+
parse_int: Callable[[str], Any] | None = None,
86+
parse_constant: Callable[[str], Any] | None = None,
87+
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None,
88+
**kwds: Any,
89+
) -> Any: ...
90+
6191
def detect_encoding(
6292
b: bytes | bytearray,
6393
) -> Literal["utf-8", "utf-8-sig", "utf-16", "utf-16-be", "utf-16-le", "utf-32", "utf-32-be", "utf-32-le"]: ... # undocumented

stdlib/json/decoder.pyi

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from collections.abc import Callable
23
from typing import Any
34

@@ -12,21 +13,38 @@ class JSONDecodeError(ValueError):
1213
def __init__(self, msg: str, doc: str, pos: int) -> None: ...
1314

1415
class JSONDecoder:
16+
if sys.version_info >= (3, 15):
17+
array_hook: Callable[[list[Any]], Any] | None
1518
object_hook: Callable[[dict[str, Any]], Any]
1619
parse_float: Callable[[str], Any]
1720
parse_int: Callable[[str], Any]
1821
parse_constant: Callable[[str], Any]
1922
strict: bool
2023
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any]
21-
def __init__(
22-
self,
23-
*,
24-
object_hook: Callable[[dict[str, Any]], Any] | None = None,
25-
parse_float: Callable[[str], Any] | None = None,
26-
parse_int: Callable[[str], Any] | None = None,
27-
parse_constant: Callable[[str], Any] | None = None,
28-
strict: bool = True,
29-
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
30-
) -> None: ...
24+
if sys.version_info >= (3, 15):
25+
def __init__(
26+
self,
27+
*,
28+
object_hook: Callable[[dict[str, Any]], Any] | None = None,
29+
parse_float: Callable[[str], Any] | None = None,
30+
parse_int: Callable[[str], Any] | None = None,
31+
parse_constant: Callable[[str], Any] | None = None,
32+
strict: bool = True,
33+
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
34+
array_hook: Callable[[list[Any]], Any] | None = None,
35+
) -> None: ...
36+
37+
else:
38+
def __init__(
39+
self,
40+
*,
41+
object_hook: Callable[[dict[str, Any]], Any] | None = None,
42+
parse_float: Callable[[str], Any] | None = None,
43+
parse_int: Callable[[str], Any] | None = None,
44+
parse_constant: Callable[[str], Any] | None = None,
45+
strict: bool = True,
46+
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
47+
) -> None: ...
48+
3149
def decode(self, s: str, _w: Callable[..., Any] = ...) -> Any: ... # _w is undocumented
3250
def raw_decode(self, s: str, idx: int = 0) -> tuple[Any, int]: ...

0 commit comments

Comments
 (0)