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

Enable exception_handler to handle Pyright's strict mode #762

Merged
merged 1 commit into from
May 12, 2023
Merged

Enable exception_handler to handle Pyright's strict mode #762

merged 1 commit into from
May 12, 2023

Conversation

paulzakin
Copy link
Contributor

@paulzakin paulzakin commented May 11, 2023

Without enabling the callable to take any # of inputs and return Any as the type, Pyright will complain with these two errors:

Type of "exception_handler" is partially unknown
Type of "exception_handler" is "(exc_class: Type[Exception]) -> ((...) -> Unknown)"Pylance[reportUnknownMemberType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUnknownMemberType)
Untyped function decorator obscures type of function; ignoring decoratorPylance[reportUntypedFunctionDecorator](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUntypedFunctionDecorator)

Hence, you need to disable those checks for this line. The typing adjustment I am advocating for fixes that!

@api.exception_handler(  # pyright: ignore [reportUntypedFunctionDecorator, reportUnknownMemberType]
    Exception
)

Also, I think the urls property in main.py is typed in a way that does not Django happy. In urls.py

path("api/", api.urls), results in:

Argument of type "Tuple[List[URLResolver | URLPattern], str, str]" cannot be assigned to parameter "view" of type "List[URLResolver | str]" in function "path"
  "Tuple[List[URLResolver | URLPattern], str, str]" is incompatible with "List[URLResolver | str]"Pylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)

while `path("api/", api.urls[0])` results in:

Argument of type "List[URLResolver | URLPattern]" cannot be assigned to parameter "view" of type "List[URLResolver | str]" in function "path"
  "List[URLResolver | URLPattern]" is incompatible with "List[URLResolver | str]"
    TypeVar "_T@list" is invariant
      Type "URLResolver | URLPattern" cannot be assigned to type "URLResolver | str"
        Type "URLPattern" cannot be assigned to type "URLResolver | str"
          "URLPattern" is incompatible with "URLResolver"

I thought worth bringing to your attention!

@vitalik vitalik merged commit 1fa3090 into vitalik:master May 12, 2023
37 checks passed
@vitalik
Copy link
Owner

vitalik commented May 12, 2023

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants