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

as_view() is not compatible with the view argument of path #514

Open
albertjan opened this issue Nov 21, 2023 · 3 comments
Open

as_view() is not compatible with the view argument of path #514

albertjan opened this issue Nov 21, 2023 · 3 comments
Labels
bug Something isn't working pyright Related to pyright type checker

Comments

@albertjan
Copy link

Bug report

What's wrong

For this line:

path("auth-test/", apitest.AuthTest.as_view()),

we get the following type error:

..../urls.py:70:9 - error: Argument of type "AsView[GenericView]" cannot be assigned to parameter "view" of type "Sequence[URLResolver | str]" in function "path"
    "AsView[GenericView]" is incompatible with "Sequence[URLResolver | str]" (reportGeneralTypeIssues)

How is that should be

Since it works the types should also be compatible right?!

System information

  • OS: MacOS Ventura 13.5 (22G74)
  • python version: Python 3.11.6
  • django version: 4.2.7
  • pyright version: pyright 1.1.336
  • django-stubs version:
django-stubs==4.2.6
django-stubs-ext==4.2.5
djangorestframework-stubs==3.14.4
@albertjan albertjan added the bug Something isn't working label Nov 21, 2023
@intgr
Copy link
Contributor

intgr commented Nov 21, 2023

First, note that pyright is not officially supported by TypedDjango project although we're open to improvements that help other type checkers.

Note that path() is an overloaded function with multiple signatures: https://github.com/typeddjango/django-stubs/blob/82c394fbdc1461d0d483162577fac50e9cacd605/django-stubs/urls/conf.pyi#L18-L28
It's weird that pyright singles out one of the multiple signatures in its error message.

The first signature with view: Callable[..., HttpResponseBase] should match AsView[GenericView], because AsView.__call__ is defined as the _View typevar, which in this case is GenericView.

And GenericView's __call__ signature def __call__(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response should be compatible with the callable.

This works in my projects with mypy. If you figure out why pyright doesn't agree with this chain of reasoning, we might be able to come up with a fix or work-around.

@intgr intgr added the pyright Related to pyright type checker label Nov 21, 2023
@albertjan
Copy link
Author

Thanks! I'll investigate a little more. 😊

@j-osephlong
Copy link

This has been my main issue in adopting drf stubs, this getting fixed would be great 😊

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

No branches or pull requests

3 participants