Skip to content

Add support for multiple files per POST field - #1032

Merged
florimondmanca merged 10 commits into
encode:masterfrom
euri10:771_multiple_files_upload_same_field
Jun 24, 2020
Merged

florimondmanca merged 10 commits into
encode:masterfrom
euri10:771_multiple_files_upload_same_field

Conversation

@euri10

@euri10 euri10 commented Jun 24, 2020 •

Copy link
Copy Markdown
Contributor

fixes #777
inspired by great work done on #891
separates files and data as per @florimondmanca suggesiton in gitter
I commented below a mypy error I ignored because I'm clueless on how to deal with it to be honest

Comment thread httpx/_content_streams.py Outdated

for name, value in files.items():
file_items = files.items() if isinstance(files, dict) else files
for name, value in file_items: # type: ignore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No idea how to fix the mypy error on this line httpx/_content_streams.py:332: error: Unpacking a string is disallowed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it’s because the type hints is using Mapping but we’re only matching against dict (a specific type of mapping), so mypy assumes that the other branch could also receive other types of mappings, and iterating over a mapping yields its keys (strings).

It’s actually possible to isinstance(obj, typing.Mapping) (since it’s the same Mapping class than in collections.abc), so I think we can go for that?

Alternatively, switch the if to match a tuple (and treat the default case as mapping) - probably a bit less surprising.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed !

@florimondmanca florimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

Comment thread tests/test_content_streams.py Resolved
Comment thread docs/advanced.md Resolved
Comment thread docs/advanced.md Resolved

@florimondmanca florimondmanca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @euri10 🎉

@florimondmanca florimondmanca changed the title multiple files upload same field Add support for multiple files per POST field Jun 24, 2020
@florimondmanca
florimondmanca merged commit 4d28795 into encode:master Jun 24, 2020
@euri10
euri10 deleted the 771_multiple_files_upload_same_field branch June 24, 2020 17:44
Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support for multiple files per POST field

2 participants