-
-
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
Model.object and djangos @classproperties not working since 1.13.1 #1285
Comments
A possible workaround would be to to remove the type hints. That probably signals mypy to leave out the function. |
This error is correct. Only Model classes have this attribute, not instances. Try |
As for the |
ahhh thank you, that's correct! the Model.object problem is fixed now :-) |
This comment was marked as off-topic.
This comment was marked as off-topic.
@dlesbre Please open a separate issue, tracking multiple different problems in one issue gets messy. |
The stub for django.test.testcases.LiveServerTestCase looks currenty look like this: django-stubs/django-stubs/test/testcases.pyi Lines 256 to 265 in 090aea6
mypy complains about the accessed classproperties e.g. I tried to set some other type hints instead of What kind of did work, was to replace The python typing docs say:
So I guess the |
What finally did work for me (based on my previous comments last concerns) was to just set the classproperties as simple attributes in the type stub without any decorators: class LiveServerTestCase(TransactionTestCase):
host: str
port: int
...
live_server_url: str
allowed_host: str I will create a pull request for that and hope you agree to this solution. |
Edit: Oh, sorry, I had some old commit checked out. I think I see the bug now. |
Indeed, classproperty was broken, fixed in #1287. |
thanks :) I reviewed your PR and applied the patch locally. that fixes the problem too - and more correctly :) |
Bug 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
pip install django-stubs==1.13.1
pip install django-stubs==1.13.0
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
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 #1150 the object property was moved from Model to ModelBase - but that doesn't work for me.
Maybe also related issues:
cannot access classproperties
Results in:
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
python
version: 3.10.4django
version: 4.1.4mypy
version: 0.991django-stubs
version: 1.13.1django-stubs-ext
version: 0.7.0The text was updated successfully, but these errors were encountered: