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

Improve typing support for the files parameter #976

Merged
merged 1 commit into from
May 21, 2020

Conversation

florimondmanca
Copy link
Member

@florimondmanca florimondmanca commented May 21, 2020

When files is passed from a variable, mypy raises an error due to us using a Dict with union values:

files = {"example": ("file name", "file content")}
_ = httpx.post("...", files=files)
error: Argument "files" to "post" has incompatible type "Dict[str, Tuple[str, str]]"; expected "Optional[Dict[str, Union[Union[IO[str], IO[bytes], str, bytes], Tuple[Optional[str], Union[IO[str], IO[bytes], str, bytes]], Tuple[Optional[str], Union[IO[str], IO[bytes], str, bytes], Optional[str]]]]]"
note: "Dict" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance
note: Consider using "Mapping" instead, which is covariant in the value type

This PR fixes this small UX bug. :-)

(Progressing on #650 would allow us to catch more of these earlier.)

@florimondmanca florimondmanca added the user-experience Ensuring that users have a good experience using the library label May 21, 2020
Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@florimondmanca florimondmanca merged commit f1b3d74 into master May 21, 2020
@florimondmanca florimondmanca deleted the multipart-mapping branch May 21, 2020 15:34
@tomchristie tomchristie mentioned this pull request May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants