Skip to content

fix: add type hints to ClientOptions #735

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

Merged
merged 5 commits into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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