-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Custom managers broken with mypy 1.5.0 #1648
Comments
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
@andersk I'm getting this error which i think is caused by the same thing:
so happy to help test any fix when its available as would like to switch to mypy 1.5.0 when possible. |
#1649 seems to fix most of the failures. |
@andersk just installed from that PR and can confirm it fixed my error. Had no other errors switching to 1.5.0. Thanks |
confirmed to, with the fix from #1649 there are no other errors switching to mypy 1.5.0. |
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
Related symptom from from django.contrib.auth.models import User
user = User.objects.create_user(username="user") Generates a type checking error on Mypy 1.5.0:
|
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
I just started seeing this error from Pyright (only in CI). I assume it's due to their latest release fixing the same bug that |
@tylerlaprade use |
@sobolevn, thanks for the response! However, my error is coming from Pyright, not from mypy, so it still persists even after I made that change. |
I don't think django-stubs is tested to work with pyright. I mean, it works with pyright in vscode for the purpose of autocomplete, but there are no tests to ensure that pyright works as a linter. Especially considering that django-stubs provides a mypy plugin to infer quite a lot of useful stuff but pyright does not support plugins and never going to. I'd suggest using a more mature and reliable mypy for type checking on CI. If it's, for some reason, not an option for your project, take a look at django-types, a community fork specifically designed to be compatible with pyright. |
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
mypy 1.5.0 was fixed to understand that metaclass attributes take precedence over attributes in the regular class. So we need to declare `objects` in the regular class to allow it to be overridden in subclasses. Fixes typeddjango#1648. Signed-off-by: Anders Kaseorg <[email protected]>
Bug report
What's wrong
Mypy 1.5.0 was just released and breaks lots of django-stubs tests. Obviously that’s semi-expected since 1.5.0 is outside the
django-stubs[compatible-mypy]
bound ofmypy==1.4.*
. But upon investigating anyway, I think mypy is correct that there’s a django-stubs problem here. The failures began withwhich fixes mypy to understand that metaclass attributes take precedence over attributes defined in regular classes, matching Python’s runtime behavior. Unfortunately, django-stubs was relying on the previous misunderstanding:
django-stubs/django-stubs/db/models/base.pyi
Lines 21 to 29 in 325006c
django-stubs/django-stubs/contrib/contenttypes/models.pyi
Lines 14 to 18 in 325006c
mypy 1.4.1 thinks
ContentType.objects
has typeContentTypeManager
, but mypy 1.5.0 thinksContentType.objects
has typeBaseManager[ContentType]
from the metaclass.This affects real projects too, such as Zulip (after bumping its pinned version of mypy):
How is that should be
We need to somehow convince mypy 1.5.0 that
ContentType.objects
has typeContentTypeManager
.System information
python
version: 3.10.2django
version: 4.2.4mypy
version: 1.5.0django-stubs
version: 4.2.3django-stubs-ext
version: 4.2.2The text was updated successfully, but these errors were encountered: