When some of the fields in a ModelSerializer (but probably any serializer) has the same name as the annotated properties of the class Field in rest_framework-stubs.fields.pyi, e.g. source, required, etc., mypy raises an assignment error.
Example:
class MatchSerializer(serializers.ModelSerializer):
source = MatchSourceSerializer()
...
This results in the following mypy error:
Incompatible types in assignment (expression has type "MatchSourceSerializer", base class "Field" defined the type as "Union[Callable[..., Any], str, None]")
If I change the type of source in fields.pyi like this:
When some of the fields in a
ModelSerializer
(but probably any serializer) has the same name as the annotated properties of the classField
inrest_framework-stubs.fields.pyi
, e.g.source
,required
, etc., mypy raises an assignment error.Example:
This results in the following mypy error:
If I change the type of
source
infields.pyi
like this:mypy now raises the following error
System information
python
version: 3.7django
version: 3.1.12djangorestframework
version: 3.12.2mypy
version: 0.812django-stubs
version: 1.8.0djangorestframework-stubs
version: 1.4.0NOTE: This is similar to https://github.com/typeddjango/djangorestframework-stubs/issues/78, but not the same issue