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 for with statement for Client class #538

Closed
nnaka2992 opened this issue Mar 2, 2021 · 3 comments · Fixed by #540
Closed

Support for with statement for Client class #538

nnaka2992 opened this issue Mar 2, 2021 · 3 comments · Fixed by #540
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@nnaka2992
Copy link

Is your feature request related to a problem? Please describe.
Currently, the Client class does not support with statement. Supporting with statement would make programmers easy to write and maintenance their code.

Describe the solution you'd like
Add __enter__ and __exit__ methods to enable with statement. Works as following would be perfect.

with bigquery.Client(location='Asia/Tokyo') as client:
    query_job = client.query("SELECT CURRENT_DATE('Asia/Tokyo');")
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Mar 2, 2021
@plamut
Copy link
Contributor

plamut commented Mar 3, 2021

@nnaka2992 What would be the expected behavior here?

Presumably, __enter__() would simply return the client instance, i.e. self, and __exit__() would invoke the client's close() method?

This could be added, yes, thanks for the suggestion.

@plamut plamut added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Mar 3, 2021
@plamut plamut self-assigned this Mar 3, 2021
@nnaka2992
Copy link
Author

Yes, that is what i meant. just return self and close is good enough.
thanks

@plamut
Copy link
Contributor

plamut commented Mar 4, 2021

OK great, this is exactly what I did in the PR, thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants