Skip to content

Commit

Permalink
fix: add type hints to ClientOptions (#735)
Browse files Browse the repository at this point in the history
* Update

* Update client_options.py

* Update

* fix build

---------

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
rinarakaki and parthea authored Oct 19, 2024
1 parent 46b3d3a commit b91ed19
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions google/api_core/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ def get_client_cert():
"""

from typing import Callable, Mapping, Optional, Sequence, Tuple


class ClientOptions(object):
"""Client Options used to set options on clients.
Args:
api_endpoint (Optional[str]): The desired API endpoint, e.g.,
compute.googleapis.com
client_cert_source (Optional[Callable[[], (bytes, bytes)]]): A callback
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback
which returns client certificate bytes and private key bytes both in
PEM format. ``client_cert_source`` and ``client_encrypted_cert_source``
are mutually exclusive.
client_encrypted_cert_source (Optional[Callable[[], (str, str, bytes)]]):
client_encrypted_cert_source (Optional[Callable[[], Tuple[str, str, bytes]]]):
A callback which returns client certificate file path, encrypted
private key file path, and the passphrase bytes.``client_cert_source``
and ``client_encrypted_cert_source`` are mutually exclusive.
Expand Down Expand Up @@ -88,15 +90,17 @@ class ClientOptions(object):

def __init__(
self,
api_endpoint=None,
client_cert_source=None,
client_encrypted_cert_source=None,
quota_project_id=None,
credentials_file=None,
scopes=None,
api_key=None,
api_audience=None,
universe_domain=None,
api_endpoint: Optional[str] = None,
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
client_encrypted_cert_source: Optional[
Callable[[], Tuple[str, str, bytes]]
] = None,
quota_project_id: Optional[str] = None,
credentials_file: Optional[str] = None,
scopes: Optional[Sequence[str]] = None,
api_key: Optional[str] = None,
api_audience: Optional[str] = None,
universe_domain: Optional[str] = None,
):
if client_cert_source and client_encrypted_cert_source:
raise ValueError(
Expand All @@ -114,11 +118,11 @@ def __init__(
self.api_audience = api_audience
self.universe_domain = universe_domain

def __repr__(self):
def __repr__(self) -> str:
return "ClientOptions: " + repr(self.__dict__)


def from_dict(options):
def from_dict(options: Mapping[str, object]) -> ClientOptions:
"""Construct a client options object from a mapping object.
Args:
Expand Down

0 comments on commit b91ed19

Please sign in to comment.