-
-
Notifications
You must be signed in to change notification settings - Fork 478
Django-stubs > 5.1.1 causes VSCode to infer model field types as Any instead of expected types #2534
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
Comments
Sorry, I have no idea how pylance works, it is not supported officially. If you know how to fix it, please send a PR. |
Sure, would like to open PR once I figure out what's the right way to do so. |
What i have read from other issue reports, here is the conclusion in for your case:
Given your code example, with django-stubs (5.1.3) installed: BTW: in case you wondered I used inlay hints in vscode, to show the inferred types inline. When you remove django-stubs library or manually install django-types stubs, you would see this: With django-stubs, to make all type checkers happy (including pyre) you would need to do the following: I noticed there is quite good discussion here about django-stubs compared to django-types: #579 |
Thanks @jhassine - removing py.typed worked for us as well. Is there hope for a package-default solution to resolve this? |
@ebk46 ok. Depends what you mean by "package-default solution"? Just a note for you based on my experiences: instead of removing How I see, one should decide whether to use Personally I prefer However I admit it's a bit confusing, took a while for me to understand as well. Ideally Second best would be to have more complete documentation how to make |
@jhassine I meant is this something the maintainers of We are still on Django 4.2 so |
@ebk46 ok. Well, I am not the maintainer but have understood that contributions in the form of PRs are welcomed 😅 Hmm, I have been using mypy 1.15 for a good while already and haven't noticed anything strange compared to the previous versions. What kind of issues you have? I have understood, mypy 1.15 is officially supported by the project since version 5.1.3 and the py.typed marker was added in 5.1.2 so they are pretty close. So I am not sure if your issues are related now to mypy or something else? |
@jhassine I did some investigation and for some reason uninstalling and reinstalling django-stubs resolved what I was seeing. Not sure what kind of conflicts there were, but I was seeing the following:
That I did try django-types and, maybe I'm missing something, but it didn't seem to work at all in our project. Foreign key relationships were typed as ForeignKey rather than the object they referenced. |
Bug report
What's wrong
After upgrading to
django-stubs
version > 5.1.1, VSCode's type intelligence no longer correctly infers the type of model fields. Specifically, it treats fields asAny
instead of their expected types.Reproduction
Minimal example:
Expected Behavior
Observations
How is that should be
VSCode should correctly infer the type of model fields, just like in django-stubs 5.1.1. The expected behavior is:
System information
python
version: 3.11django
version: 5.1mypy
version: 1.13.0django-stubs
version: 5.1.3django-stubs-ext
version: 5.1.3The text was updated successfully, but these errors were encountered: