-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Annotation Errors in Models Inheriting from 3rd Party Packages #2341
Comments
One other fun tidbit of information: not all fields throw an error.
|
I believe I'm getting the same issue - it asks for |
I get similar issue with related managers - many of them are not resolved with update to 5.0.4, but a couple of them could be fixed if a model inherited from #1354 seems relevant. |
It tried to do a bisect and it seems the issue was maybe introduced in ac36393. |
Getting this with:
|
Here is a monkeypatch workaround: import mypy_django_plugin.lib.helpers
from mypy_django_plugin.lib.helpers import is_model_type as patch
allowlist = {
"dotted.path.to.your.ModelClass",
}
def is_model_type(info):
if info.fullname in allowlist:
return True
return patch(info)
mypy_django_plugin.lib.helpers.is_model_type = is_model_type It seems that for models inherited from 3rd party apps, |
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:
django-cookiecutter
.mypy
v1.11.1,django-stubs
v5.0.4, and tested withDjango
4.2.11 and 5.0.8.local_app/models.py
, there are no errors.FooBase
class to a 3rd party package’smodels.py
(e.g.,site-packages/django_extensions/models.py
since that came with the cookiecutter install), I get a mypy error on theupdated_at
field 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
python
version: 3.11.9django
version: 5.0.8 & 4.2.11mypy
version: 1.11.1django-stubs
version: 5.0.4django-stubs-ext
version: 5.0.4mypy Settings
The text was updated successfully, but these errors were encountered: