fix(google-auth): invalid TYPE_CHECKING imports in google/auth/_default.py cause Unknown types in Pyright

Open
#19,077 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@sakshamgoyal-01 is already working on this.

Since Nov 13, 2026.

  • #19078 by @sakshamgoyal-01 — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

The problem is in the TYPE_CHECKING block at the top of google/auth/_default.py, which imports the classes google.auth.credentials.Credentials and google.auth.transport.Request as if they were modules. Check the annotations on default() to see where Pyright reports Unknown. Pull request 19078 is already open against this issue, so review that first. Done means the block imports the modules and Pyright no longer reports Unknown for default().

Written by the indexing model from the issue text.

Description

(Note: This is an AI-generated issue.)

Problem

In google/auth/_default.py, the TYPE_CHECKING block attempts to import classes as if they were submodules:

if TYPE_CHECKING:  # pragma: NO COVER
    import google.auth.credentials.Credentials  # type: ignore
    import google.auth.transport.Request  # type: ignore

Because Credentials and Request are classes (not submodules), these imports fail to resolve and are suppressed with # type: ignore. As a result, type checkers like Pyright / BasedPyright resolve the annotations on google.auth.default():

def default(
    scopes: Optional[Sequence[str]] = None,
    request: Optional["google.auth.transport.Request"] = None,
    quota_project_id: Optional[str] = None,
    default_scopes: Optional[Sequence[str]] = None,
) -> tuple["google.auth.credentials.Credentials", Optional[str]]:

as Unknown (e.g., (..., request: Unknown | None = None, ...) -> tuple[Unknown, str | None]), triggering reportUnknownVariableType / reportUnknownMemberType warnings for callers.

Suggested Fix

Import the modules instead of the classes in the TYPE_CHECKING block:

if TYPE_CHECKING:  # pragma: NO COVER
    import google.auth.credentials
    import google.auth.transport
Dominant language
Python
Stars
5.4k
Forks
1.8k
Avg merge
2d 7h
Merged PRs (30d)
173

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-cloud-python

All issues in googleapis/google-cloud-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.