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

Generate AsyncClient from Client #310

Merged
merged 4 commits into from
Apr 11, 2023
Merged

Generate AsyncClient from Client #310

merged 4 commits into from
Apr 11, 2023

Conversation

grahamalama
Copy link
Contributor

@grahamalama grahamalama commented Apr 5, 2023

This PR abstracts the pattern we were using before of wrapping most Client methods in a loop.run_in_executor into some metaprogramming.

I wouldn't exactly call this approach sustainable. We'll run into issues any time we reuse a public method inside another public method, since we won't await the call in the Client but will need to in the AsyncClient. This happened to me in this PR with _create_if_not_exists and _delete_if_exists.

As long as we don't foresee the public API of this client changing soon and constrain ourselves to only using private methods in public methods, we can merge this. Or, we can redouble our efforts to make the Async client truly async-compatible from the ground up, since I'm not sure just wrapping the Client methods in loop.run_in_executor(None, func) cuts it.

@grahamalama grahamalama requested review from leplatrem and matt-boris and removed request for matt-boris April 5, 2023 17:49
@grahamalama grahamalama marked this pull request as draft April 5, 2023 17:49
Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

💯

def async_client(cls):
for name, method in inspect.getmembers(cls, inspect.isfunction):
if not (name.startswith("_") or name == "clone"):
setattr(cls, name, async_wrap(method))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@grahamalama grahamalama force-pushed the generate-async-client branch from 98d81a4 to dd7613b Compare April 6, 2023 15:02
@grahamalama grahamalama marked this pull request as ready for review April 6, 2023 15:03
@grahamalama grahamalama changed the title [WIP] Generate AsyncClient from Client Generate AsyncClient from Client Apr 6, 2023
@grahamalama grahamalama requested a review from leplatrem April 6, 2023 15:26
@grahamalama
Copy link
Contributor Author

Might wait for #308 before fixing the linting on this

Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

I like to see these many duplicated lines removed 🤩

As long as we don't foresee the public API of this client changing soon and constrain ourselves to only using private methods in public methods, we can merge this.

The public API hasn't changed for a long time, and the constraint to use only private methods in public ones is not too bad.

@grahamalama grahamalama merged commit 643835a into master Apr 11, 2023
@grahamalama grahamalama deleted the generate-async-client branch April 11, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants