Skip to content

Using unpack to keep parameters when creating httpx subclass leads to crash #17208

@CarliJoy

Description

@CarliJoy

Crash Report

Just use a TypedDict when creating a subclass leads to a crash

Traceback

Traceback (most recent call last):
  File "mypy/checker.py", line 591, in accept
  File "mypy/nodes.py", line 787, in accept
  File "mypy/checker.py", line 1000, in visit_func_def
  File "mypy/checker.py", line 1011, in _visit_func_def
  File "mypy/checker.py", line 1901, in check_method_override
  File "mypy/checker.py", line 1936, in check_method_or_accessor_override_for_base
  File "mypy/checker.py", line 2045, in check_method_override_for_base_with_name
  File "mypy/checker.py", line 2219, in check_override
IndexError: list index out of range

To Reproduce

from typing import Any, TypedDict, Unpack

import httpx
from httpx._client import UseClientDefault
from httpx._types import (
    AuthTypes,
    CookieTypes,
    HeaderTypes,
    QueryParamTypes,
    RequestContent,
    RequestData,
    RequestExtensions,
    RequestFiles,
    TimeoutTypes,
    URLTypes,
)


class RequestExtraArgs(TypedDict, total=False):
    params: QueryParamTypes | None
    headers: HeaderTypes | None
    cookies: CookieTypes | None
    follow_redirects: bool | UseClientDefault
    timeout: TimeoutTypes | UseClientDefault
    extensions: RequestExtensions | None


class SyncClient(httpx.Client):
    def request(
        self,
        method: str,
        url: URLTypes,
        *,
        content: RequestContent | None = None,
        data: RequestData | None = None,
        files: RequestFiles | None = None,
        json: Any | None = None,
        auth: AuthTypes | None = None,
        **extra_args: Unpack[RequestExtraArgs],
    ) -> httpx.Response:
        """
        Build and send a request.

        See: ``httpx.Client.request()``.
        """
        response = super().request(method, url, **extra_args)
        return response

Your Environment

  • Mypy version used: master
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11
  • Operating system and version: linux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions