[Bug Report] `TransformerBridge.boot_*` methods are invisible to static type checkers

未关闭 适合新手
#1,980 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@koriyoshi2041 已经在做这个了。

开始于 2026年11月5日。

  • #1981 来自 @koriyoshi2041 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

阅读 transformer_lens/model_bridge.py 以及报告中提到的三个源码位置:sources/transformers/__init__.py:31、sources/native/__init__.py:115 和 sources/tl_legacy.py:226。比较 boot_* 的签名,并决定如何向静态类型检查器公开这些签名,同时保持从 bridge 到 sources 的导入方向。完成标准是,像 TransformerBridge.boot_native(cfg) 这样的调用能够被识别,并具有带类型的返回值。

由索引模型根据 Issue 内容生成。

描述

bug complexity-simple TransformerBridge

boot_transformers, boot_native and boot_tl_legacy are attached to TransformerBridge at import time with setattr(TransformerBridge, "boot_...", staticmethod(boot)), in sources/transformers/__init__.py:31, sources/native/__init__.py:115 and sources/tl_legacy.py:226. Because the class body never declares them, static type checkers flag every call, even though the package ships py.typed:

from transformer_lens.model_bridge import TransformerBridge
model = TransformerBridge.boot_native(cfg)
# ty: Class `TransformerBridge` has no attribute `boot_native`

It also means no autocomplete and an untyped return value in editors.

Workaround: from transformer_lens.model_bridge.sources import boot_native. This works and is fully typed.

Possible fixes, which keep the bridge → sources import direction intact:

  • Declare the methods on the class under if TYPE_CHECKING:, using the source signatures, or
  • Define them as real @staticmethods on TransformerBridge that lazily import and delegate to the source boot.

Versions: transformer-lens 4.3.0, ty 0.0.97, Python 3.14

主要语言
Python
星标
3.9k
派生
708
平均合并
1 天 4 小时
30 天内合并 PR
87

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TransformerLensOrg/TransformerLens 的其他 Issue

查看 TransformerLensOrg/TransformerLens 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。