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

Fix APIException detail types nesting #438

Merged
merged 1 commit into from
Jun 27, 2023
Merged
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
8 changes: 4 additions & 4 deletions rest_framework-stubs/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ErrorDetail(str):
code: str | None
def __new__(cls, string: str, code: str | None = ...): ...

_Detail: TypeAlias = ErrorDetail | list[ErrorDetail] | dict[str, ErrorDetail]
_Detail: TypeAlias = ErrorDetail | list[_Detail] | dict[str, _Detail]
# NB! _APIExceptionInput doesn't technically handle Sequence/Mapping, but only list/tuple/dict.
# But since list/tuple are non-covariant types, we run into issues with union type compatibility for input params.
# So use the more relaxed Sequence/Mapping for now.
Expand All @@ -24,7 +24,7 @@ class _FullDetailDict(TypedDict):
message: ErrorDetail
code: str | None

_ErrorFullDetails: TypeAlias = _FullDetailDict | list[_FullDetailDict] | dict[str, _FullDetailDict]
_ErrorFullDetails: TypeAlias = _FullDetailDict | list[_ErrorFullDetails] | dict[str, _ErrorFullDetails]

def _get_error_details(data: _APIExceptionInput, default_code: str | None = ...) -> _Detail: ...
def _get_codes(detail: _Detail) -> _ErrorCodes: ...
Expand All @@ -41,8 +41,8 @@ class APIException(Exception):
def get_full_details(self) -> _ErrorFullDetails: ...

class ValidationError(APIException):
# ValidationError always wraps `detail` in a list.
detail: list[ErrorDetail] | dict[str, ErrorDetail]
# ValidationError wraps `detail` in a list if it's not already a list/dict.
detail: list[_Detail] | dict[str, _Detail]

class ParseError(APIException): ...
class AuthenticationFailed(APIException): ...
Expand Down