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

Async for files.py functions #586

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

shilpakancharla
Copy link
Collaborator

Added asyncio methods for all the file methods.

However, how should we test these asyncio methods?

@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:python sdk Issue/PR related to Python SDK labels Oct 5, 2024
@@ -97,6 +111,10 @@ def list_files(page_size=100) -> Iterable[file_types.File]:
yield file_types.File(proto)


async def list_files_async(*args, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will fail because we want an async iterator to be returned here.

Can you copy the list_files code and add the missing asyncs?

@@ -105,6 +123,10 @@ def get_file(name: str) -> file_types.File:
return file_types.File(client.get_file(name=name))


async def get_file_async(*args, **kwargs):
return await asyncio.to_thread(get_file, *args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have an async client, we should use it. Let's copy-paste the code, and add the missing asyncs

@@ -114,3 +136,7 @@ def delete_file(name: str | file_types.File | protos.File):
request = protos.DeleteFileRequest(name=name)
client = get_default_file_client()
client.delete_file(request=request)


async def delete_file_async(*args, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same.

@@ -127,5 +130,29 @@ def test_files_delete(self):
# [END files_delete]


class AsyncTests(absltest.TestCase, unittest.IsolatedAsyncioTestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should test all the methods, I think list is broken right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK status:awaiting review PR awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants