typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.61k stars 452 forks source link

django-stubs breaks PyCharm code completion in some contexts #1807

Open urzbs opened 1 year ago

urzbs commented 1 year ago

Bug report

What's wrong

Using a django project created with a the cookiecutter/django-cookiecutter/ template (Pycharm as IDE)

autocompletion of attributes / methods of certain classes no longer work.

example tests with some class-based-views:

import logging
from django.views.generic import CreateView, DetailView, DeleteView, UpdateView

logger = logging.getLogger(__name__)

class MyCreateView(CreateView):
    # nothing is no longer autocompleted / suggested
class MyDeleteView(DeleteView):
    # nothing is no longer autocompleted / suggested
class MyUpdateView(UpdateView):
    # nothing is no longer autocompleted / suggested

# However DetailView still works with all auto-completions

class MyDetailView(DetailView):
    template_name = "" # this is still autocompleted
    def get_queryset(self) -> models.query.QuerySet[_M]: # this is still autocompleted ...

How is that should be

Like normal, you can see what the class offers for attributes / methods...

System information

intgr commented 1 year ago

Hi! I think this issue is on PyCharm's side: https://youtrack.jetbrains.com/issue/PY-37744/django-stubs-breaks-code-completion (do add a :+1: vote if you have an account there)

Maksim Kurnikov reached out to them, but according to this reply there is nothing we can do on our side.

I'll leave this bug open so if anyone else is struggling with it, it's easier to find

intgr commented 5 months ago

Looks like PY-37744 has been just recently fixed by JetBrains and will be part of the next PyCharm release (and IntelliJ Python plugin).