Closed
Description
Bug report
What's wrong
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 information
- OS: macOS
python
version: 3.10.11django
version: 4.2.5mypy
version: 1.5.1django-stubs
version: 4.2.4django-stubs-ext
version: 4.2.2
Mypy 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",
]