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

未關閉
#19,077 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@sakshamgoyal-01 已經在處理了。

開始於 2026年11月13日。

  • #19078 來自 @sakshamgoyal-01 —— 未關閉

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python

研究方向

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().

由索引模型根據 Issue 內容生成。

描述

(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
主要語言
Python
星號
5.4k
分支
1.8k
平均合併
2 天 7 小時
30 天內合併 PR
173

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

googleapis/google-cloud-python 的其他 Issue

查看 googleapis/google-cloud-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。