Skip to content

Question about httpx.Client constructor parameter proxies #2131

@chagui

Description

@chagui

Hello,
Thanks for the great library!

I just ran into a mypy error for the following code.

def fun(proxies: httpx.Proxy | None) -> None:
    with httpx.Client(proxies=proxies):
        pass
error: Argument "proxies" to "Client" has incompatible type "Optional[Proxy]"; expected "Union[Union[URL, str], Proxy, Dict[Union[URL, str], Union[None, Union[URL, str], Proxy]]]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

I find this surprising because the httpx.Client constructor parameter proxies is advertised as optional:

  • proxies - (optional) A dictionary mapping proxy keys to proxy
    URLs.

https://github.com/encode/httpx/blob/master/httpx/_client.py#L598-L599

It's also the default value for the parameter:

proxies: ProxiesTypes = None,

https://github.com/encode/httpx/blob/master/httpx/_client.py#L626

Should the type be changed to typing.Optional[ProxiesTypes] or am I missing something?

I could not find any existing issue related to this but if I somehow miss it feel free to point me to it and close this one 😇

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions