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

Support fuller files kwarg for requests.post #743

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

semperos
Copy link

Thanks for taking the time to review this! I ran into this type mismatch with some code that leverages the requests library and was hoping to update responses to match.


The files keyword argument for the requests.post function has this type:

files: _Files | None = ...

This commit adds this type alias as found in requests version 2.32.2 and updates this library's multipart_matcher function's files keyword argument to be of type _Files.

The files keyword argument for the requests.post function has this type:

files: _Files | None = ...

This commit adds this type alias as found in requests version 2.32.2 and
updates this library's multipart_matcher function's files keyword
argument to be of type _Files.
@beliaev-maksim
Copy link
Collaborator

should we just import it from requests then ?

@markstory
Copy link
Member

should we just import it from requests then ?

👍 to importing the types if we can.

@semperos
Copy link
Author

I neglected to run tox before pushing that last commit, there are errors; I'll fix them before pushing again, no need to approve the workflows.

@semperos
Copy link
Author

I believe Python's import prevents importing names with a leading underscore; I get an ImportError: cannot import name '_Files' from 'requests.sessions' when I attempt to from requests.sessions import _Files.

Two paths forward that I see:

  1. Ask the requests maintainers to expose this type.
  2. Recreate the types here.

The original PR workflow run showed that the syntax I ported from requests of tuple[_FileName, _FileContent] breaks in Python 3.8. If we go with option 2, I can adjust the type syntax to make the code compatible with Python 3.8.

@beliaev-maksim
Copy link
Collaborator

can you please send a permalink to the piece of code at requests where they define the type?

@semperos
Copy link
Author

Apologies for not double-checking the source of the types, I had jumped to them in my editor and didn't realize they weren't provided by the requests implementation itself. The types I included in my first commit were from typeshed.

Here is the permalink to where _Files is used: https://github.com/python/typeshed/blob/7cae61f61a042a772010274dd1d8f1ee4454e5a4/stubs/requests/requests/sessions.pyi#L148

Here is the permalink to the definition of _Files itself: https://github.com/python/typeshed/blob/7cae61f61a042a772010274dd1d8f1ee4454e5a4/stubs/requests/requests/sessions.pyi#L92

@beliaev-maksim
Copy link
Collaborator

so, if we add a dependency and import the type, will it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants