Skip to content

fix(types): add full type annotations to transport init for Mypy strict mode (#1508) #1720

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
57 changes: 28 additions & 29 deletions google/auth/transport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import abc
import http.client as http_client
from typing import Optional, Mapping, Any


DEFAULT_RETRYABLE_STATUS_CODES = (
http_client.INTERNAL_SERVER_ERROR,
Expand All @@ -36,7 +38,6 @@
"""Sequence[int]: HTTP status codes indicating a request can be retried.
"""


DEFAULT_REFRESH_STATUS_CODES = (http_client.UNAUTHORIZED,)
"""Sequence[int]: Which HTTP status code indicate that credentials should be
refreshed.
Expand All @@ -49,19 +50,22 @@
class Response(metaclass=abc.ABCMeta):
"""HTTP Response data."""

@abc.abstractproperty
def status(self):
"""int: The HTTP status code."""
@property
@abc.abstractmethod
def status(self) -> int:
"""The HTTP status code."""
raise NotImplementedError("status must be implemented.")

@abc.abstractproperty
def headers(self):
"""Mapping[str, str]: The HTTP response headers."""
@property
@abc.abstractmethod
def headers(self) -> Mapping[str, str]:
"""The HTTP response headers."""
raise NotImplementedError("headers must be implemented.")

@abc.abstractproperty
def data(self):
"""bytes: The response body."""
@property
@abc.abstractmethod
def data(self) -> bytes:
"""The response body."""
raise NotImplementedError("data must be implemented.")


Expand All @@ -70,34 +74,29 @@ class Request(metaclass=abc.ABCMeta):

Specific transport implementations should provide an implementation of
this that adapts their specific request / response API.

.. automethod:: __call__
"""

@abc.abstractmethod
def __call__(
self, url, method="GET", body=None, headers=None, timeout=None, **kwargs
):
self,
url: str,
method: str = "GET",
body: Optional[bytes] = None,
headers: Optional[Mapping[str, str]] = None,
timeout: Optional[int] = None,
**kwargs: Any,
) -> Response:
"""Make an HTTP request.

Args:
url (str): The URI to be requested.
method (str): The HTTP method to use for the request. Defaults
to 'GET'.
body (bytes): The payload / body in HTTP request.
headers (Mapping[str, str]): Request headers.
timeout (Optional[int]): The number of seconds to wait for a
response from the server. If not specified or if None, the
transport-specific default timeout will be used.
kwargs: Additionally arguments passed on to the transport's
request method.
url: The URI to be requested.
method: The HTTP method to use. Defaults to 'GET'.
body: The payload / body of the HTTP request.
headers: Request headers.
timeout: Timeout in seconds.
kwargs: Extra transport-specific request options.

Returns:
Response: The HTTP response.

Raises:
google.auth.exceptions.TransportError: If any exception occurred.
"""
# pylint: disable=redundant-returns-doc, missing-raises-doc
# (pylint doesn't play well with abstract docstrings.)
raise NotImplementedError("__call__ must be implemented.")