When configured to enable the optional explicit-override error, mypy unexpectedly flags explicit-override errors for the generated get_FOO_display, get_next_by_FOO, get_previous_by_FOO methods on subclasses of models having fields with choices, DateFields, and DateTimeFields.
Example
pyproject.toml
[tool.mypy]
enable_error_code = ["explicit-override"]
plugins = ["mypy_django_plugin.main"]
[tool.django-stubs]
django_settings_module = "myapp.settings"
myapp/__init__.py
myapp/settings.py
INSTALLED_APPS = ["myapp"]
myapp/models.py
from django.db import models
class A(models.Model):
which = models.IntegerField(choices=((1, "one"), (2, "two")))
when = models.DateTimeField()
class B(A):
pass
mypy output
$ mypy .
myapp/models.py:7: error: Method "get_which_display" is not using @override but is overriding a method in class "myapp.models.A" [explicit-override]
myapp/models.py:7: error: Method "get_next_by_when" is not using @override but is overriding a method in class "myapp.models.A" [explicit-override]
myapp/models.py:7: error: Method "get_previous_by_when" is not using @override but is overriding a method in class "myapp.models.A" [explicit-override]
Found 3 errors in 1 file (checked 3 source files)
(Expected no errors.)
When configured to enable the optional
explicit-overrideerror, mypy unexpectedly flagsexplicit-overrideerrors for the generatedget_FOO_display,get_next_by_FOO,get_previous_by_FOOmethods on subclasses of models having fields withchoices,DateFields, andDateTimeFields.Example
pyproject.tomlmyapp/__init__.pymyapp/settings.pymyapp/models.pymypy output
(Expected no errors.)