Skip to content

Added missing types#16666

Draft
Tesla2000 wants to merge 1 commit intogoogleapis:mainfrom
Tesla2000:python-interface
Draft

Added missing types#16666
Tesla2000 wants to merge 1 commit intogoogleapis:mainfrom
Tesla2000:python-interface

Conversation

@Tesla2000
Copy link
Copy Markdown

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 #15176 🦕

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 15, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Tesla2000
Copy link
Copy Markdown
Author

Tesla2000 commented Apr 15, 2026

Still requires adjustments but marking so you know someone is willing to work on it

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds type hints to various modules within the google-auth library and introduces a new internal helper file. The review identifies critical issues where stub syntax was incorrectly used in Python implementation files, which would cause runtime failures. Furthermore, the feedback points out several missing imports for type annotations, numerous redundant duplicate imports, and the need for specific type ignore markers when handling optional dependencies.

Comment on lines +65 to +94
class _RequestMethodsBase: ...

class TimeoutGuard:
remaining_timeout: Any

def __init__(
self,
timeout: Any,
timeout_error_type: type[Exception] = requests.exceptions.Timeout,
) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: types.TracebackType | None,
) -> None: ...

class _MutualTlsAdapter(HTTPAdapter):
def __init__(self, cert: bytes, key: bytes) -> None: ...
def init_poolmanager(self, *args: Any, **kwargs: Any) -> None: ...
def proxy_manager_for(self, *args: Any, **kwargs: Any): ...

class _MutualTlsOffloadAdapter(HTTPAdapter):
signer: Any

def __init__(self, enterprise_cert_file_path: str) -> None: ...
def init_poolmanager(self, *args: Any, **kwargs: Any) -> None: ...
def proxy_manager_for(self, *args: Any, **kwargs: Any): ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

These class definitions use stub syntax (...) in a .py file. This will overwrite any existing implementations with empty classes and methods, breaking the library's functionality at runtime. Additionally, requests and types are used in these definitions but are not imported. Type definitions should be added to the actual implementation or provided in a separate .pyi stub file.

Comment on lines +3 to +20
@type_check_only
class _BaseAuthorizedSession(metaclass=abc.ABCMeta):
credentials: Any

def __init__(self, credentials: Any) -> None: ...
@abc.abstractmethod
def request(
self,
method: str,
url: str,
data: Any = None,
headers: Any = None,
max_allowed_time: Any = None,
timeout: int = ...,
**kwargs: Any,
): ...
@abc.abstractmethod
def close(self) -> None: ... No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

This file contains several issues that will cause runtime errors:

  1. abc and abc.ABCMeta are used but not imported.
  2. @type_check_only is used but not imported or defined. This decorator is typically used in stub files (.pyi), not implementation files (.py).
  3. The use of ... and ellipsis in default values is also characteristic of stub files.
    If this file is intended to be a runtime helper, it needs proper imports and implementation. If it's intended to be a stub, it should be renamed to _helpers.pyi.

from collections import OrderedDict
from typing import TypeVar

_Key = TypeVar("_Key", bound=Hashable)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The type hint Hashable is used but not imported. It should be imported from collections.abc.

Suggested change
_Key = TypeVar("_Key", bound=Hashable)
_Key = TypeVar("_Key", bound=collections.abc.Hashable)

def load_credentials_from_file(
filename, scopes=None, default_scopes=None, quota_project_id=None, request=None
):
filename: str, scopes: collections.abc.Sequence[str] | None=None, default_scopes: collections.abc.Sequence[str] | None=None, quota_project_id: str | None=None, request: Request | None=None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The type hint Request is used but not imported in this file. It should be imported from google.auth.transport.

from google.auth import _helpers
from google.auth import exceptions
from google.auth._credentials_base import _BaseCredentials
from google.auth.transport import Request as _TransportRequest, Request as _TransportRequest, Request as _TransportRequest, Request as _TransportRequest, Request as _TransportRequest, Request as _TransportRequest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Duplicate import of Request as _TransportRequest. Remove duplicate lines of code to keep the codebase clean and avoid redundancy.

References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

from google.auth import exceptions
from google.auth import jwt
from google.auth.transport import requests
from google.auth.transport import Request as _Request, Request as _Request, Request as _Request, Request as _Request, requests
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Duplicate import of Request as _Request. Remove duplicate lines of code to keep the codebase clean and avoid redundancy.

Suggested change
from google.auth.transport import Request as _Request, Request as _Request, Request as _Request, Request as _Request, requests
from google.auth.transport import Request as _Request, requests
References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

from google.oauth2 import _client_async
from google.oauth2 import challenges
from google.oauth2 import reauth
from google.auth.transport import Request as _Request, Request as _Request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Duplicate import of Request as _Request. Remove duplicate lines of code to keep the codebase clean and avoid redundancy.

References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

from google.auth import _helpers
from google.oauth2 import _client_async
from google.oauth2 import service_account
from google.auth.transport import Request as _Request, Request as _Request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Duplicate import of Request as _Request. Remove duplicate lines of code to keep the codebase clean and avoid redundancy.

References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

from google.auth import metrics
from google.oauth2 import _client
from google.oauth2 import challenges
from google.auth.transport import Request as _Request, Request as _Request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Duplicate import of Request as _Request. Remove duplicate lines of code to keep the codebase clean and avoid redundancy.

References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

import urllib

from google.oauth2 import utils
from google.auth.transport import Request as _Request, Request as _Request, Request as _Request
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Duplicate import of Request as _Request. Remove duplicate lines of code to keep the codebase clean and avoid redundancy.

References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mypy strict mode issues: "Call to untyped function in typed context"

1 participant