Skip to content

Commit cce59b5

Browse files
Add type hints to JSON utility methods in rest_framework.utils (#633)
1 parent 9a05c05 commit cce59b5

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

rest_framework-stubs/utils/json.pyi

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
1-
from typing import Any, NoReturn
1+
from json import JSONDecoder, JSONEncoder
2+
from typing import IO, Any, Callable, NoReturn
23

34
def strict_constant(o: Any) -> NoReturn: ...
4-
def dump(*args: Any, **kwargs: Any) -> None: ...
5-
def dumps(*args: Any, **kwargs: Any) -> str: ...
6-
def load(*args: Any, **kwargs: Any) -> Any: ...
7-
def loads(*args: Any, **kwargs: Any) -> Any: ...
5+
def dump(
6+
obj: Any,
7+
fp: IO[str],
8+
*,
9+
skipkeys: bool = False,
10+
ensure_ascii: bool = True,
11+
check_circular: bool = True,
12+
allow_nan: bool = True,
13+
cls: type[JSONEncoder] | None = None,
14+
indent: int | str | None = None,
15+
separators: tuple[str, str] | None = None,
16+
default: Callable[[Any], Any] | None = None,
17+
sort_keys: bool = False,
18+
**kw: Any,
19+
) -> None: ...
20+
def dumps(
21+
obj: Any,
22+
*,
23+
skipkeys: bool = False,
24+
ensure_ascii: bool = True,
25+
check_circular: bool = True,
26+
allow_nan: bool = True,
27+
cls: type[JSONEncoder] | None = None,
28+
indent: int | str | None = None,
29+
separators: tuple[str, str] | None = None,
30+
default: Callable[[Any], Any] | None = None,
31+
sort_keys: bool = False,
32+
**kw: Any,
33+
) -> str: ...
34+
def load(
35+
fp: IO[str],
36+
*,
37+
cls: type[JSONDecoder] | None = None,
38+
object_hook: Callable[[dict[str, Any]], Any] | None = None,
39+
parse_float: Callable[[str], Any] | None = None,
40+
parse_int: Callable[[str], Any] | None = None,
41+
parse_constant: Callable[[str], Any] | None = None,
42+
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
43+
**kw: Any,
44+
) -> Any: ...
45+
def loads(
46+
s: str,
47+
*,
48+
cls: type[JSONDecoder] | None = None,
49+
object_hook: Callable[[dict[str, Any]], Any] | None = None,
50+
parse_float: Callable[[str], Any] | None = None,
51+
parse_int: Callable[[str], Any] | None = None,
52+
parse_constant: Callable[[str], Any] | None = None,
53+
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
54+
**kw: Any,
55+
) -> Any: ...

scripts/stubtest/allowlist_todo.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ rest_framework.test.APIRequestFactory.put
112112
rest_framework.test.RequestsClient.__init__
113113
rest_framework.throttling.SimpleRateThrottle.cache
114114
rest_framework.utils.encoders.JSONEncoder.default
115-
rest_framework.utils.json.dump
116-
rest_framework.utils.json.dumps
117-
rest_framework.utils.json.load
118-
rest_framework.utils.json.loads
119115
rest_framework.validators.BaseUniqueForValidator.message
120116
rest_framework.validators.ContextValidator
121117
rest_framework.validators.Validator

0 commit comments

Comments
 (0)