-
-
Notifications
You must be signed in to change notification settings - Fork 521
Description
Bug report
What's wrong
With the latest django-stubs v5.0.4, I've noticed strange behavior when using models that inherit from 3rd party packages. Specifically, mypy throws a "Need type annotation for <field_name>" error on model fields.
Here’s the scenario:
- I created a new project using
django-cookiecutter. - I added
mypyv1.11.1,django-stubsv5.0.4, and tested withDjango4.2.11 and 5.0.8. - I have the following model classes:
class FooBase(models.Model):
name = models.CharField(max_length=255)
class Meta:
abstract = True
class Bar(FooBase):
updated_at = models.DateTimeField(auto_now=True)
- When both classes are defined in
local_app/models.py, there are no errors. - However, if I move the
FooBaseclass to a 3rd party package’smodels.py(e.g.,site-packages/django_extensions/models.pysince that came with the cookiecutter install), I get a mypy error on theupdated_atfield ofBar.
This issue only started occurring with django-stubs v5.0.3 or v5.0.4 and mypy v1.11.0 or v1.11.1. It was working correctly with the previous versions (django-stubs v5.0.2 and mypy v1.10.1).
I am aware of issue #2011, which has been closed. However, the difference here is that the code was working fine with the prior django-stubs and mypy versions, but the error occurs after updating to the latest versions.
How is that should be
Type checking should pass without errors when using models that inherit from 3rd party packages, just as it did with previous versions of django-stubs and mypy.
System information
- OS: yes
pythonversion: 3.11.9djangoversion: 5.0.8 & 4.2.11mypyversion: 1.11.1django-stubsversion: 5.0.4django-stubs-extversion: 5.0.4
mypy Settings
[tool.mypy]
python_version = "3.11"
check_untyped_defs = true
ignore_missing_imports = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true
plugins = [
"mypy_django_plugin.main",
]