Skip to content

PyCharm gets weird about self.request.GET.get #799

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

Closed
Crocmagnon opened this issue Dec 28, 2021 · 6 comments
Closed

PyCharm gets weird about self.request.GET.get #799

Crocmagnon opened this issue Dec 28, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@Crocmagnon
Copy link
Contributor

Bug report

What's wrong

class ArticleDetailView(generic.DetailView):
    model = Article

    def get_queryset(self):
        key = self.request.GET.get("draft_key")

Screenshot 2021-12-28 at 23 22 50

PyCharm complains about the types here, even though mypy doesn't.

Hinting request: WSGIRequest solves the issue with PyCharm though.

How is that should be

There should not be any issue with the types. Is PyCharm wrong about complaining here? Is django-stubs wrong about typing request with HttpRequest and not something else like WSGIRequest?

System information

  • OS: macOS 12.1 (21C52)
  • python version: Python 3.10.0
  • django version: 4.0
  • mypy version: mypy 0.930
  • django-stubs version: 1.9.0
  • django-stubs-ext version: 0.3.1
@Crocmagnon Crocmagnon added the bug Something isn't working label Dec 28, 2021
@sobolevn
Copy link
Member

Can you please paste reveal_type(self.request)? What it was initially?

Looks related to python/typeshed#6597

@Crocmagnon
Copy link
Contributor Author

src/articles/views/html.py:133: note: Revealed type is "django.http.request.HttpRequest"

My guess is that comes from the existing type hinting in TemplateResponseMixin:

request: http.HttpRequest = ...

@sobolevn
Copy link
Member

Ok, here's what I think is going on.

HttpRequest has .GET defined QueryDict, which is a MuttableMapping subtype:

class MultiValueDict(MutableMapping[_K, _V]):

Related python/typeshed#6694

@Crocmagnon
Copy link
Contributor Author

Crocmagnon commented Dec 29, 2021

So it’s an error in pycharm? As a matter of fact I don’t understand their message. My .get call looks fine according to their pop up, right?

It nearly seems like they think I’m missing the self, like if GET were a type, not an instance. I’ll try to check the revealed type of GET

@sobolevn
Copy link
Member

It looks like it is a error with PyCharm. Do they use our stubs? Or do the use their own version?

You can send a PR with this sample as a test case (if we don't have one). Just to be sure.

@Crocmagnon
Copy link
Contributor Author

Crocmagnon commented Dec 29, 2021

This looks related to #555, this thread and this YouTrack issue. Nothing we can fix here I'm afraid.

BTW, Revealed type is "django.http.request.QueryDict" in both cases (with HttpRequest or WSGIRequest as type for self.request).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants