Skip to content

SanicASGITestClient has wrong type hints #79

@pdmtt

Description

@pdmtt

Hello there!

SanicASGITestClient inherits from httpx.AsyncClient and override its request method, changing its return type.

class SanicASGITestClient(httpx.AsyncClient):
    async def request(  # type: ignore
        self, method, url, gather_request=True, *args, **kwargs
    ) -> typing.Tuple[
        typing.Optional[Request], typing.Optional[TestingResponse]
    ]:
      ...
class AsyncClient(BaseClient):
    async def request(
        self,
        method: str,
        url: URL | str,
        *,
        content: RequestContent | None = None,
        data: RequestData | None = None,
        files: RequestFiles | None = None,
        json: typing.Any | None = None,
        params: QueryParamTypes | None = None,
        headers: HeaderTypes | None = None,
        cookies: CookieTypes | None = None,
        auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
        follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
        timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
        extensions: RequestExtensions | None = None,
    ) -> Response:
      ...

httpx.AsyncClient's HTTP verbs methods return from the request method and this behaviour isn't overrided by SanicASGITestClient.

That makes Pycharm believe SanicASGITestClient.get's return type is httpx.Response, but it actually is typing.Optional[Request], typing.Optional[TestingResponse].

I believe this might happen to other IDEs as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions