You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(This works fine, but IDE will complain about async_file type)
Desktop (please complete the following information):
OS: Ubuntu 22.04
Python Version: 3.11
openapi-python-client version: 0.24.1
Additional context
Quick solution:
@defineclassFile:
""" Contains information for file uploads """payload: BinaryIO|AsyncFilefile_name: Optional[str] =Nonemime_type: Optional[str] =None
But:
Running upload.asyncio function with payload of type BinaryIO will result in the following exception: Runtime Error: Attempted to send an sync request with an AsyncClient instance.
So, to prevent users from getting this a little bit misleading exception, they should get an IDE warning. To do that, asyncio functions should require a different type of payload than sync, when it comes to IO objects:
@defineclassFile:
""" Contains information for file uploads """payload: BinaryIOfile_name: Optional[str] =Nonemime_type: Optional[str] =None
[.....]
fromanyioimportAsyncFile@defineclassAsyncFile_:
""" Contains information for file uploads """payload: AsyncFilefile_name: Optional[str] =Nonemime_type: Optional[str] =None
The text was updated successfully, but these errors were encountered:
Describe the bug
LOW PRIORITY
If an API provides an "upload_file" endpoint, when using async, one has to use an asynchronous way to open a file.
Using anyio from httpx, it would require an "AsyncFile" object:
https://github.com/agronholm/anyio/blob/2a63fd0bef1575e583c4cf63cebe7d76a218c83e/src/anyio/_core/_fileio.py#L38C49-L39C5
This doesn't match with File payload typehint:
openapi_python_client/templates/types.py.jinja, line 25
and results with an incorrect IDE warning.
OpenAPI Spec File
https://github.com/openapi-generators/openapi-python-client/blob/main/openapi_python_client/templates/types.py.jinja#L25
Example async usage:
(This works fine, but IDE will complain about
async_file
type)Desktop (please complete the following information):
Additional context
Quick solution:
But:
Running upload.asyncio function with payload of type BinaryIO will result in the following exception:
Runtime Error: Attempted to send an sync request with an AsyncClient instance.
So, to prevent users from getting this a little bit misleading exception, they should get an IDE warning. To do that, asyncio functions should require a different type of payload than sync, when it comes to IO objects:
The text was updated successfully, but these errors were encountered: