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

feat: add type hints to Client #2044

Merged
merged 8 commits into from
Dec 10, 2024
Merged

Conversation

rinarakaki
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@rinarakaki rinarakaki requested review from a team as code owners October 21, 2024 10:32
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Oct 21, 2024
Copy link

conventional-commit-lint-gcf bot commented Oct 21, 2024

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Oct 21, 2024
Comment on lines 244 to 249
if client_options is None:
client_options = {}
if isinstance(client_options, dict):
client_options = google.api_core.client_options.from_dict(client_options)
assert isinstance(client_options, google.api_core.client_options.ClientOptions)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am curious, why did we choose to:

  • move this content from after the call to super() to before the call to super()? What is the reason for reordering this content?
  • add an assert statement when one was not used previously?

Copy link
Contributor Author

@rinarakaki rinarakaki Nov 22, 2024

Choose a reason for hiding this comment

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

  • Moving this part before the call to super() is optional, but I did it because actually the exact same type check & coercion happens inside the super() (Client.__init__) as well, so I let it early break in the second time.
  • The reason for adding the assert statement is to let the type checker know the type of client_options, otherwise it wouldn't know that the if client_options.api_endpoint: expression at the line 261 is valid .

@chalmerlowe chalmerlowe added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 25, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 25, 2024
@chalmerlowe
Copy link
Collaborator

@rinarakaki I ran the kokoro CI/CD checks.
There are a number of things that are going wrong both in the standard tests and in mypy.
I spent as much time as I could today trying to trouble shoot the issues, to no avail.
I have other tasks that require my attention. If you are able to figure out why these tests fail I am willing to come back and take another look at this.

mypy errors:

google/cloud/bigquery/client.py:265: error: Incompatible types in assignment
   (expression has type "str", target has type "Optional[ClientInfo]")  [assignment]
google/cloud/bigquery/client.py:269: error: Incompatible types in assignment
   (expression has type "str", target has type "Optional[ClientInfo]")  [assignment]

unit test errors:

tests/unit/conftest.py:19: in 
    from .helpers import make_client
tests/unit/helpers.py:19: in 
    import google.cloud.bigquery.client
google/cloud/bigquery/__init__.py:36: in 
    from google.cloud.bigquery.client import Client
google/cloud/bigquery/client.py:185: in 
    class Client(ClientWithProject):
google/cloud/bigquery/client.py:235: in Client
    _http: Optional[requests.Session] = None,
E   NameError: name 'requests' is not defined

chalmerlowe and others added 4 commits December 4, 2024 07:31
@chalmerlowe chalmerlowe added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@chalmerlowe chalmerlowe added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
testing some minor changes to deal with mypy quirks
@chalmerlowe chalmerlowe added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@chalmerlowe chalmerlowe added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 10, 2024
Copy link
Collaborator

@chalmerlowe chalmerlowe left a comment

Choose a reason for hiding this comment

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

LGTM

@chalmerlowe chalmerlowe merged commit 40529de into googleapis:main Dec 10, 2024
17 checks passed
@chalmerlowe
Copy link
Collaborator

@rinarakaki

Thanks for providing this update to the code.

@rinarakaki rinarakaki deleted the typing-client branch December 11, 2024 04:33
chalmerlowe added a commit that referenced this pull request Jan 2, 2025
* add type hints

* Update client.py

Moves import from being used solely during specific checks to being more universally available.

* Update google/cloud/bigquery/client.py

* Update client.py

testing some minor changes to deal with mypy quirks

* Update google/cloud/bigquery/client.py

---------

Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
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. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants