You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is all perfectly fine code, but mypy is complaining here: Argument 1 to "ValidationError" has incompatible type "ErrorDict"; expected "_APIExceptionInput".
Here's the actual class from DRF:
classValidationError(APIException):
status_code=status.HTTP_400_BAD_REQUESTdefault_detail=_('Invalid input.')
default_code='invalid'def__init__(self, detail=None, code=None):
ifdetailisNone:
detail=self.default_detailifcodeisNone:
code=self.default_code# For validation failures, we may collect many errors together,# so the details should always be coerced to a list if not already.ifisinstance(detail, tuple):
detail=list(detail)
elifnotisinstance(detail, dict) andnotisinstance(detail, list):
detail= [detail]
self.detail=_get_error_details(detail, code)
And the implementation of _get_error_details:
def_get_error_details(data, default_code=None):
""" Descend into a nested data structure, forcing any lazy translation strings or strings into `ErrorDetail`. """ifisinstance(data, (list, tuple)):
ret= [
_get_error_details(item, default_code) foritemindata
]
ifisinstance(data, ReturnList):
returnReturnList(ret, serializer=data.serializer)
returnretelifisinstance(data, dict):
ret= {
key: _get_error_details(value, default_code)
forkey, valueindata.items()
}
ifisinstance(data, ReturnDict):
returnReturnDict(ret, serializer=data.serializer)
returnrettext=force_str(data)
code=getattr(data, 'code', default_code)
returnErrorDetail(text, code)
As you can see, a dict is perfectly fine here, so it seems that the types from djangorestframework-stubs are too restrictive? I'm using djangorestframework-stubs[compatible-mypy]>=3.15.2.
Passing in self.set_password_form.errors.as_data() didn't solve the typing error either.
The text was updated successfully, but these errors were encountered:
Consider this serializer:
This is all perfectly fine code, but mypy is complaining here:
Argument 1 to "ValidationError" has incompatible type "ErrorDict"; expected "_APIExceptionInput"
.Here's the actual class from DRF:
And the implementation of
_get_error_details
:As you can see, a dict is perfectly fine here, so it seems that the types from djangorestframework-stubs are too restrictive? I'm using
djangorestframework-stubs[compatible-mypy]>=3.15.2
.Passing in
self.set_password_form.errors.as_data()
didn't solve the typing error either.The text was updated successfully, but these errors were encountered: