Prior to django-stubs
4.2.4 / mypy
1.5.1, the you could type hint a variable/class attribute as type[Model]
and access .objects
on it:
from django.contrib.auth.models import User from django.db.models import Model user_type: type[Model] = User users = user_type.objects.all()
Note that is the real usage, the variable is a class variable that is set by derived classes.
But as of the latest django-stubs
and mypy
, this generates a type check error:
error: "type[Model]" has no attribute "objects" [attr-defined]
How is that should be
No type check errors.
System informationpython
version: 3.10.11django
version: 4.2.5mypy
version: 1.5.1django-stubs
version: 4.2.4django-stubs-ext
version: 4.2.2Mypy configuration:
[tool.mypy] ignore_missing_imports = true strict = true disallow_subclassing_any = false disallow_untyped_decorators = false warn_return_any = false plugins = [ "pydantic.mypy", "mypy_django_plugin.main", ]
sidmitra, meshy, IoanStoianov, rob4226, totycro and 3 more
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4