Model.object and djangos @classproperties not working since 1.13.1
See original GitHub issueBug report
Hello 😃 first of all thank you very much for releasing the new version 1.13.1 so quickly after I asked for it! But now I am facing two new problems, which might be related so I’m posting them together.
Steps to reproduce
See my separately crafted repo with minimal steps to reproduce: https://github.com/djbrown/mypy-django-bugs
But basically it’s:
pip install django mypy django-stubs==1.13.0
- generate simple django project and include above bug snippets
- execute mypy check -> ✔
pip install django-stubs==1.13.1
- execute mypy check -> ❌
pip install django-stubs==1.13.0
- execute mypy check -> ✔
So it’s definitely the new version… I can also add a failing test or workflow so you don’t have to reproduce manually.
[Collapsed: This part of the report was resolved]
no attribute Model.objects
from django.db.models import Model
def invalid(model: Model):
model.objects
Results in error: "Model" has no attribute "objects" [attr-defined]
I already tried to fix by enabling monkey-patching in settings.py or module via django_stubs_ext or use ModelBase or TypeVar instead of Model.
Because in https://github.com/typeddjango/django-stubs/pull/1150 the object property was moved from Model to ModelBase - but that doesn’t work for me.
Maybe also related issues:
cannot access classproperties
from django.test import LiveServerTestCase
class ServerTestCase(LiveServerTestCase):
def invalid(self, arg: str):
self.live_server_url
Results in:
error: Argument 1 to "__get__" of "classproperty" has incompatible type "ServerTestCase"; expected "Optional[classproperty[Any]]" [arg-type]
error: Argument 2 to "__get__" of "classproperty" has incompatible type "Type[ServerTestCase]"; expected "Type[classproperty[Any]]" [arg-type]
I already tried to fix by enabling monkey-patching in settings.py or module via django_stubs_ext, or access classproperty via class or super class. Accessing normal class attributes works fine though.
System information
- OS: ubuntu
python
version: 3.10.4django
version: 4.1.4mypy
version: 0.991django-stubs
version: 1.13.1django-stubs-ext
version: 0.7.0
Issue Analytics
- State:
- Created 9 months ago
- Comments:12 (10 by maintainers)
thanks 😃 I reviewed your PR and applied the patch locally. that fixes the problem too - and more correctly 😃
Done #1286