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

Open Beginner friendly
#1,980 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Read transformer_lens/model_bridge.py and the three source locations named in the report: sources/transformers/__init__.py:31, sources/native/__init__.py:115, and sources/tl_legacy.py:226. Compare the boot_* signatures and decide how to expose them to static type checkers while preserving the bridge-to-sources import direction. Done when calls such as TransformerBridge.boot_native(cfg) are recognized and have a typed return value.

Written by the indexing model from the issue text.

Description

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

Dominant language
Python
Stars
3.9k
Forks
708
Avg merge
1d 10h
Merged PRs (30d)
82

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

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 TransformerLensOrg/TransformerLens

All issues in TransformerLensOrg/TransformerLens

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.