Skip to content

Commit d619e26

Browse files
authored
Fix APIException detail types nesting (#438)
The `_Detail`, `_ErrorFullDetails` and `ValidationError.detail` types allow arbitrary nesting, but this was omitted by mistake from the original pull request. The other related types `_APIExceptionInput` and `_ErrorCodes` were already recursive.
1 parent 92c9ef1 commit d619e26

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

rest_framework-stubs/exceptions.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ErrorDetail(str):
1111
code: str | None
1212
def __new__(cls, string: str, code: str | None = ...): ...
1313

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

27-
_ErrorFullDetails: TypeAlias = _FullDetailDict | list[_FullDetailDict] | dict[str, _FullDetailDict]
27+
_ErrorFullDetails: TypeAlias = _FullDetailDict | list[_ErrorFullDetails] | dict[str, _ErrorFullDetails]
2828

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

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

4747
class ParseError(APIException): ...
4848
class AuthenticationFailed(APIException): ...

0 commit comments

Comments
 (0)