Skip to content

refactor(mypy): un-ignore metrics/metric module#288

Merged
woodsh17 merged 4 commits into
RosettaCommons:productionfrom
lyskov-ai:0006-ratchet-mypy-metric
Jun 3, 2026
Merged

refactor(mypy): un-ignore metrics/metric module#288
woodsh17 merged 4 commits into
RosettaCommons:productionfrom
lyskov-ai:0006-ratchet-mypy-metric

Conversation

@lyskov-ai
Copy link
Copy Markdown
Contributor

Type-checking: fix the 11 type errors in foundry.metrics.metric and remove it from the [tool.mypy.overrides] ignore_errors list (6 → 5 remaining), so mypy now type-checks the module. No behavior change.

What changed

  • str(name) coercion in the config loop — DictConfig.items() types keys as a str|bytes|int|… union; metric names are strings (fixes 1 arg-type + 2 str-bytes-safe).
  • exists(x)x is not None in Metric.__init__ — atomworks' exists is literally obj is not None, but mypy can't narrow through the helper; the direct check lets set(...) see list|set. Drops the now-orphaned from atomworks.common import exists import.
  • Widened compute_from_kwargsdict | list to match the abstract compute's declared return. The sole caller (MetricManager.__call__) already branches on isinstance(result, dict) / isinstance(result, list).
  • Widened base kwargs_to_compute_argsdict | None to match the docstring ("we return None") and every caller's guard. Subclass overrides (mpnn, outside mypy scope) return a plain dict — a compatible narrower override.
  • Three # type: ignore[arg-type] on nested_dict.get/getitem — genuine upstream annotation bug: atomworks types the first param as dict[tuple[str, ...], Any] but navigates a nested dict[str, Any] by string keys. Passing kwargs is correct at runtime; warn_unused_ignores = true will flag these if upstream is corrected.

lyskov-ai and others added 3 commits June 3, 2026 03:24
Fix each module's single pre-existing type error with a pure annotation
or setattr change (no behavior change) and remove it from the
[[tool.mypy.overrides]] ignore_errors list:

- callbacks/train_logging: loss_trackers: dict[str, MeanMetric]
- callbacks/metrics_logging: seen_examples: set[str]
- common: setattr(wrapper, "_has_run", True) for the @wraps wrapper
- hydra/resolvers: attribute_path: str | None (body already guards)
- inference_engines/base: base_overrides: dict[str, Any]

13 modules remain on the ignore list. mypy now type-checks the 5
newly-included modules cleanly.

Co-authored-by: Sergey Lyskov <sergey.lyskov@jhu.edu>
Resolve the type errors in and remove from the [[tool.mypy.overrides]]
ignore_errors list. Mostly narrowing / annotation fixes; two deliberate
type-honesty fixes flagged below.

- utils/weights: lowercase `any` -> `Any` in _PatternPolicyMixin (4x);
  assert-narrow fallback_policy at the call site (matches get_policy idiom)
- model/layers/blocks: class-level w/b: torch.Tensor for the registered
  buffers (avoids nn.Module's Tensor | Module __getattr__ fallback)
- utils/components: is-None narrowing + tip_names local in get_name_mask's
  TIP branch (exists() can't narrow for mypy); drop orphaned exists import
- utils/logging: str(field) for the tree key; assign to a new hparams local
  rather than reassigning the typed cfg param
- foundry_cli/download_checkpoints: guard on `hasher is not None`;
  total_size = 0.0 for the float accumulation
- training/schedulers: SchedulerConfig.scheduler is now a required field
  (was = None, but documented required and assumed non-None everywhere)
- utils/xpu/xpu_accelerator: name @Property -> @staticmethod to match
  lightning's Accelerator ABC

6 hard-tier modules remain on the ignore list.

Co-authored-by: Sergey Lyskov <sergey.lyskov@jhu.edu>
Fix the 11 type errors in foundry.metrics.metric and remove it from the
[tool.mypy.overrides] ignore_errors list (5 hard-tier modules remain).

- str(name) coercion of DictConfig.items() keys (str|bytes|int|... union)
- exists() -> 'is not None' narrowing; drop orphaned atomworks import
- widen compute_from_kwargs -> dict|list and kwargs_to_compute_args -> dict|None
  to match the actual returns / documented contract (callers already handle them)
- three type: ignore[arg-type] on nested_dict.get/getitem for an upstream
  atomworks annotation bug (param typed dict[tuple,...] but navigated as nested
  dict[str,Any]); warn_unused_ignores will flag them if upstream is fixed

No behavior change. All gates green (ruff, mypy 41 files, pytest 27 passed).

Co-authored-by: Sergey Lyskov <sergey.lyskov@jhu.edu>
@lyskov-ai lyskov-ai force-pushed the 0006-ratchet-mypy-metric branch from d57ed1f to acbcf8a Compare June 3, 2026 03:25
@woodsh17 woodsh17 merged commit 497307e into RosettaCommons:production Jun 3, 2026
4 checks passed
@lyskov-ai lyskov-ai deleted the 0006-ratchet-mypy-metric branch June 3, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants