Skip to content

Commit

Permalink
Add type hints to JSON utility methods in rest_framework.utils (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
DongwookKim0823 authored Jul 3, 2024
1 parent 9a05c05 commit cce59b5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
58 changes: 53 additions & 5 deletions rest_framework-stubs/utils/json.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
from typing import Any, NoReturn
from json import JSONDecoder, JSONEncoder
from typing import IO, Any, Callable, NoReturn

def strict_constant(o: Any) -> NoReturn: ...
def dump(*args: Any, **kwargs: Any) -> None: ...
def dumps(*args: Any, **kwargs: Any) -> str: ...
def load(*args: Any, **kwargs: Any) -> Any: ...
def loads(*args: Any, **kwargs: Any) -> Any: ...
def dump(
obj: Any,
fp: IO[str],
*,
skipkeys: bool = False,
ensure_ascii: bool = True,
check_circular: bool = True,
allow_nan: bool = True,
cls: type[JSONEncoder] | None = None,
indent: int | str | None = None,
separators: tuple[str, str] | None = None,
default: Callable[[Any], Any] | None = None,
sort_keys: bool = False,
**kw: Any,
) -> None: ...
def dumps(
obj: Any,
*,
skipkeys: bool = False,
ensure_ascii: bool = True,
check_circular: bool = True,
allow_nan: bool = True,
cls: type[JSONEncoder] | None = None,
indent: int | str | None = None,
separators: tuple[str, str] | None = None,
default: Callable[[Any], Any] | None = None,
sort_keys: bool = False,
**kw: Any,
) -> str: ...
def load(
fp: IO[str],
*,
cls: type[JSONDecoder] | None = None,
object_hook: Callable[[dict[str, Any]], Any] | None = None,
parse_float: Callable[[str], Any] | None = None,
parse_int: Callable[[str], Any] | None = None,
parse_constant: Callable[[str], Any] | None = None,
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
**kw: Any,
) -> Any: ...
def loads(
s: str,
*,
cls: type[JSONDecoder] | None = None,
object_hook: Callable[[dict[str, Any]], Any] | None = None,
parse_float: Callable[[str], Any] | None = None,
parse_int: Callable[[str], Any] | None = None,
parse_constant: Callable[[str], Any] | None = None,
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
**kw: Any,
) -> Any: ...
4 changes: 0 additions & 4 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ rest_framework.test.APIRequestFactory.put
rest_framework.test.RequestsClient.__init__
rest_framework.throttling.SimpleRateThrottle.cache
rest_framework.utils.encoders.JSONEncoder.default
rest_framework.utils.json.dump
rest_framework.utils.json.dumps
rest_framework.utils.json.load
rest_framework.utils.json.loads
rest_framework.validators.BaseUniqueForValidator.message
rest_framework.validators.ContextValidator
rest_framework.validators.Validator
Expand Down

0 comments on commit cce59b5

Please sign in to comment.