-
Notifications
You must be signed in to change notification settings - Fork 765
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
Django stubs are out of date and cause erroneous type errors #6029
Comments
Thanks for the issue. We actually pull django stubs from here: That's because the other django stubs (https://github.com/typeddjango/django-stubs) are mypy only and don't work with other type checkers. It's likely the types you're talking about need to be added to https://github.com/sbdchd/django-types |
Good to know! Thanks, I'll chase on that repo. I do question however whether bundling a specific version of Django types in the extension is a good idea. My proposed "fix" will help me (working on Django 5.0), but will presumably cause problems for anyone working on an older version of Django. It would be great if the extension either: a) didn't bundle a specific version of the django-stubs library at all, or; What do you think? |
I'm not sure if you meant we ship no type stubs or not, but the reason we bundle stubs is so we have type information for things which are not typed. Without type stubs you'd get very different intellisense from Django. Here's an example:
In that code above, if we remove type stubs, the type of That's because the actual function definition isn't typed at all. We can't actually figure out the type that might be returned:
Whereas the type stubs provide types:
If those type stubs aren't installed, Django is a lot harder to write (well in my opinion). That's why we ship them for some very common packages. We have to pick a version to ship, and sometimes that version is out of date. Django is a tough one because the type stubs we use are not the most commonly maintained version. We have some ideas on how to address that, but it's a bit far down our backlog. The best option for most people to get actual intellisense is to ship the latest type stubs. Most public APIs don't change all that often and when they do they're mostly additive (meaning newer type stubs work for the most part with older installs)
This might be the right idea for some people (people using older versions I'd think). Right now you can do this yourself by deleting our shipping stubs. That doesn't work so well though because you have to keep deleting them every time you upgrade. So maybe an option to disable type stubs? |
Honestly, having type stubs that are a couple of major versions out of date bundled with the extension makes Django pretty hard to write, too.
Yeah, that's the problem. This just bit me again. My Pylance extension obviously updated itself, and I spent half an hour trying to remember how I fixed the erroneous type errors in my Django code the last time I saw them. An option to disable type stubs would be really useful please. |
Incidentally, I did chase this on the source repo (sbdchd/django-types#255), but the issue hasn't been acknowledged. |
@rchiodo Any update on this one? It keeps biting our development team. A way to disable built-in type stubs would be very helpful here. |
Sorry it's not currently planned. It's on our backlog but will likely take some time to get to. I'd recommend just submitting the new types to the https://github.com/sbdchd/django-types/blob/main/django-stubs/utils/deprecation.pyi as a PR. |
https://github.com/typeddjango/django-stubs (which is more active than the https://github.com/sbdchd/django-types fork) has worked on pyright support (release notes, pull request). I don't know if it's ready but it would be nice if Pylance swapped eventually. |
@rik, that PR only started running Pyright as part of the I believe typeddjango/django-stubs#579 is the issue to watch for progress. |
The |
We should definitely test them out to see if we get better results than the stubs we were using. |
It does look like even though the pyright run is green, it is flagging a lot of errors: |
Ah right, when you expand the "Run pyright on the stubs" step. |
Is there some way I can disable the VS Code bundled django-types stubs in the meantime and instead use the django-stubs installed and configured in my project? |
@anentropic, the stubs in your |
Ugh, my problem was an old version of django-stubs in my own venv... I thought I had latest 5.1.0 and that type errors with apologies |
@rchiodo django-types seems to be outdated. Adding a simple py.typed file in django stubs got it working for me locally with pylance. I have given a PR to include the same file in their repo - typeddjango/django-stubs#2470 Hope this resolves the issue |
The Django stubs that ship with the Pylance VSCode extension are out of date, and take precedence over stubs installed in the local environment.
Environment data
Code Snippet
n/a
Repro Steps
manage.py
RemovedInDjango51Warning
on L6 is highlighted"RemovedInDjango51Warning" is unknown import symbol
Expected behavior
RemovedInDjango51Warning
is a legitimate symbol in Django 5.0.6, and should not be highlighted. If you command-click (probably ctrl-click on Linux/Windows?) ondjango.utils.deprecation
you will find it defined there.Actual behavior
See screenshot above.
This appears to be because the django stubs shipped with the Pylance extension are out of date:
Logs
The text was updated successfully, but these errors were encountered: