-
-
Notifications
You must be signed in to change notification settings - Fork 458
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
RelatedManager import moved breaking Pylance #1868
Comments
If we can figure out why pyright/pylance doesn't like
Yep, that symbol no longer exists. You may be able to resolve this by using |
Thanks! I'll try to have a look then on how Pylance works with this file |
Are you still experiencing this issue? Another user reported that If yes, please double check that you have the right version of both If that doesn't help, post what errors you are getting. |
It is possible that it is my setup that is incorrect : I can see that some symbols resolve to a django .py source file, while others resolve to a .pyi django stubs file |
Also doesn't work for me in mypy. I think we need to invert the logic here:
to
This change has fixed the issue on my end. |
I tried @baranyildirim but this make mypy crash |
Ignore my previous comment - I have a configuration that uses both pylance and mypy. Pylance definitions don't work with this solution. RelatedManager is only defined inside a function (
|
This works as in, it doesn't cause pylance to crash... but pylance resolves it to ANY |
I just encountered this problem (importing from |
I think the issue might be microsoft/pylance-release#5031, where Pylance's bundled stubs take precedence over manually installed As for #1868 (comment)
That is not correct. In |
Thanks @intgr ! I tried the fix, but:
|
I've tried the workaround. Pylance then correctly picks installed django-stubs instead of the bundled django-types, and RelatedManager can be imported from django_stubs_ext.db.models.manager. However, after being switched to django-stubs, Pylance lost the inference for the fields' types. I have to explicitly write the type hints for ForeignKey like |
I agree. |
Thank you for confirming that the suggested workaround solved the reported problem. I will close this issue as completed, I think the other problems you mention are tracked/covered by these issues:
Feel free to open any new issue/discussion if you feel that you encounter something that hasn't been reported. |
Bug report
What's wrong
from django_stubs_ext.db.models import manager
and usingrelated: manager.RelatedManager[OtherModel]
breaks Pylance type hints in VSCodefrom django.db.models import manager
and usingrelated: manager.RelatedManager[OtherModel]
breaks Mypy, but only in the same fileHow is that should be
from django_stubs_ext.db.models import manager
correctly export Django Manager so autocomplete works?System information
python
version: 3.12.0django
version: 4.2.8mypy
version: 1.7.1django-stubs
version: 4.2.7django-stubs-ext
version: 4.2.7The text was updated successfully, but these errors were encountered: