Skip to content
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

Pyright fails to find cookies member of Django's HttpResponse #5927

Closed
apollo13 opened this issue Sep 11, 2023 · 2 comments
Closed

Pyright fails to find cookies member of Django's HttpResponse #5927

apollo13 opened this issue Sep 11, 2023 · 2 comments
Labels
as designed Not a bug, working as intended bug Something isn't working

Comments

@apollo13
Copy link

Describe the bug
Pyright fails to discover members on HttResponse but only in strict mode, the following code works fine on mypy (no matter the mode).

Code or Screenshots

from typing import reveal_type

from django.http import HttpResponse

response = HttpResponse()
reveal_type(response)
print(response.cookies["_up_method"].value)

django and django-stubs are installed. The relevant type in the stubs file is defined here: https://github.com/typeddjango/django-stubs/blob/87f48b3ae62cd983c72f2e9639e80a9a7c6e487f/django-stubs/http/response.pyi#L26 -- are the stubs somehow not used or am I doing something wrong?

The output:

/home/florian/sources/unpoly/python-unpoly/test.py
  /home/florian/sources/unpoly/python-unpoly/test.py:6:13 - information: Type of "response" is "HttpResponse"
  /home/florian/sources/unpoly/python-unpoly/test.py:7:7 - error: Type of "cookies" is unknown (reportUnknownMemberType)
  /home/florian/sources/unpoly/python-unpoly/test.py:7:7 - error: Type of "value" is unknown (reportUnknownMemberType)
  /home/florian/sources/unpoly/python-unpoly/test.py:7:7 - error: Argument type is unknown
    Argument corresponds to parameter "values" in function "print" (reportUnknownArgumentType)
3 errors, 0 warnings, 1 information 

VS Code extension or command-line
pyright command-line version 1.1.326

@apollo13 apollo13 added the bug Something isn't working label Sep 11, 2023
@erictraut
Copy link
Collaborator

Pyright isn't "failing to discover members" in this case. It's simply telling you that the evaluated type of the member is Unknown. In strict mode, the reportUnknownMember diagnostic check is enabled.

This appears to be a bug in the type stubs. The response.pyi type stub declares the type of cookies as SimpleCookie. This symbol comes from cookie.pyi and is defined as a variable SimpleCookie: Any. Variables are not allowed to appear within type annotations, so pyright treats it as an Unknown type. I suspect that the intent of the stub authors was to create a type alias (SimpleCookie = Any) or a class that derives from Any (class SimpleCookie(Any): ...).

@erictraut erictraut closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
@erictraut erictraut added the as designed Not a bug, working as intended label Sep 11, 2023
@apollo13
Copy link
Author

I see, sorry for the noise. Will see about getting this fixed upstream.

apollo13 added a commit to apollo13/django-stubs that referenced this issue Sep 11, 2023
This definition makes it usable even in pyright's strict mode.
See microsoft/pyright#5927 for details.
apollo13 added a commit to apollo13/django-stubs that referenced this issue Sep 11, 2023
This definition makes it usable even in pyright's strict mode.
See microsoft/pyright#5927 for details.
apollo13 added a commit to apollo13/django-stubs that referenced this issue Sep 22, 2023
This definition makes it usable even in pyright's strict mode.
See microsoft/pyright#5927 for details.
intgr pushed a commit to typeddjango/django-stubs that referenced this issue Dec 4, 2023
…1702)

This definition makes it usable even in pyright's strict mode.
See microsoft/pyright#5927 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants