Skip to content
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

Add type hints to JSON utility methods in rest_framework.utils #633

Merged
Merged
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
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