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

オープン 初心者向け
#1,980 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python

調査の方向性

transformer_lens/model_bridge.pyと、報告で挙げられている3つのソースの場所、sources/transformers/__init__.py:31、sources/native/__init__.py:115、sources/tl_legacy.py:226を読んでください。boot_*のシグネチャを比較し、bridgeからsourcesへのインポート方向を保ちながら、静的型チェッカーにそれらを認識させる方法を決めてください。TransformerBridge.boot_native(cfg)のような呼び出しが認識され、型付けされた戻り値を持つようになれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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日 10時間
マージ済み PR(30日)
82

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TransformerLensOrg/TransformerLens のほかの issue

TransformerLensOrg/TransformerLens の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。