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 摘要。