-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
There was a problem hiding this 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
98d81a4
to
dd7613b
Compare
Might wait for #308 before fixing the linting on this |
There was a problem hiding this 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.
This PR abstracts the pattern we were using before of wrapping most
Client
methods in aloop.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 theClient
but will need to in theAsyncClient
. 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 inloop.run_in_executor(None, func)
cuts it.