Repository navigation
Conversation
koriyoshi2041
left a comment
There was a problem hiding this comment.
Verified at 3d8f746b. The focused module passes locally (24 tests), including every removed top-level name through both attribute access and from ... import .... The message assertion also guards against falling back to CPython's generic unchained ImportError, while unknown names retain normal AttributeError behavior. The documented hasattr trade-off is bounded to the removed-name set.
jlarson4
left a comment
There was a problem hiding this comment.
Great work on this! Just a couple small notes on other related areas we should probably touch as a part of this PR
koriyoshi2041
left a comment
There was a problem hiding this comment.
Rechecked at daae5940. The three follow-ups are implemented: the migration guide now documents the ImportError and feature-detection trade-off, the hook_points.HookedRootModule re-export preserves its migration pointer for both access forms, and focused regressions cover both paths. The full hosted matrix is green.
|
Hey @jlarson4 review comments are solved, let me know if you need anything from my side |
|
Thanks @MdSadiqMd, looks great! |
Description
The
_REMOVED_IN_4_0shim (added in #1759) exists so removed top-level names fail with a migration pointer instead of a bare error. It does that for attribute access:But it did not reach the
from transformer_lens import HookedTransformerspelling — which is the one downstream packages actually use (e.g.circuit_tracerdoesfrom transformer_lens import HookedTransformer, HookedTransformerConfig):CPython's from-import machinery calls
getattron the module and, onAttributeError, discards it and raises its ownImportError. The original is not chained (__cause__and__context__are bothNone), so the migration pointer is not merely hidden — it is gone. The__getattr__shim's comment anticipated the submodule case explicitly and read as though the from-import case was covered; it was the one in between that got missed, and nothing under any test path exercised it.Fix:
__getattr__now raisesImportError(notAttributeError) for removed names, withname=namemetadata. A non-AttributeErrorraised fromgetattris propagated by the from-import machinery rather than swallowed, so the pointer now reaches both spellings:Trade-off (intended, and documented in the comment):
hasattr(transformer_lens, "HookedTransformer")now raises instead of returningFalse, becausehasattronly swallowsAttributeError. Version-detection code written this way now surfaces the migration pointer rather than a silentFalse. An exception inheriting from bothImportErrorandAttributeErroris not possible (ImportError's C-level layout conflicts), so the two forms cannot be satisfied by a single type — this fixes the primary case (from-import) that downstream porting hits.Regression tests are parametrized over every name in
_REMOVED_IN_4_0and pin that both the attribute form and the from-import form reach the pointer. They accept eitherAttributeErrororImportErroron purpose, so they pin the reach-the-pointer property rather than the resolution.Not addressed here (separate concern, out of scope):
transformer_lens.__version__is absent on 4.0 and not in_REMOVED_IN_4_0, so it answers with the generic no-attribute message;importlib.metadata.version("transformer-lens")still works.Fixes #1801
Type of change
Please delete options that are not relevant.
Screenshots
N/A
Checklist: