Skip to content

fix(core): warn once for renamed names served by lazy_exports - #5530

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/lazy-exports-warn-once
Nov 3, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/lazy-exports-warn-once

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What changed and why

Package facades such as nemo_gym.config and nemo_gym.models build their __getattr__ with lazy_exports in nemo_gym/_public_api.py. A name missing from the package's export table falls back to MOVED_NAMES through moved_names_getattr(package). That getter tracks the names it has already warned about in a set held by its closure, but lazy_exports built a new getter on every access, each with an empty set. So the deprecation warning repeated:

  • from nemo_gym.config import TOKEN_ID_CAPTURE_BLOCK warned twice, because a from-import looks the name up on the package more than once.
  • Every later nemo_gym.config.TOKEN_ID_CAPTURE_BLOCK access warned again.

The fix builds the getter once per package, on the first fallback, and reuses it. Each old name now warns once, as it does when a module installs moved_names_getattr as its own __getattr__. _public_api still imports _moved_paths inside the function, so its import edges don't change.

No issue: this is a small follow-up to the package reorganization tracked in #5166. The duplicate warning showed up in #5528.

Tests

A new test in tests/unit_tests/test_moved_paths.py runs in a fresh interpreter. It records every warning, imports TOKEN_ID_CAPTURE_BLOCK from nemo_gym.config (a name that package serves only through MOVED_NAMES), then reads it again as an attribute, and checks that exactly one deprecation warning names the old path. On the code before this change it fails with three warnings.

Validation

PYTHONPATH=$PWD ~/dev/Gym/.venv/bin/python -m pytest -q -n 8 tests/unit_tests/test_moved_paths.py $(git grep -l "_public_api\|lazy_exports" tests)
pre-commit run --files nemo_gym/_public_api.py tests/unit_tests/test_moved_paths.py
pre-commit run import-linter --all-files

All pass.

Rollout evidence

N/A: only import-time deprecation warnings change. No environment, agent, or verifier behavior changes.

Compatibility

Code that imports a renamed name from a package facade now sees one deprecation warning instead of several. Once this and #5528 both land, the facade test in #5528 can tighten from "one distinct message" to "exactly one warning".

A package facade built by lazy_exports resolved a name missing from its
export table through a new moved_names_getattr getter on every access.
Each getter starts with an empty record of warned names, so a from-import,
which looks the name up more than once, warned twice, and every later
attribute access warned again. Build the getter on first use and keep it,
so each old name warns once, as it does for a module's own __getattr__.
_moved_paths is still imported inside the function.

Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ananthsub
ananthsub marked this pull request as ready for review November 3, 2026 19:40
@ananthsub
ananthsub merged commit 80cc55d into main Nov 3, 2026
12 of 13 checks passed
@ananthsub
ananthsub deleted the ananthsub/lazy-exports-warn-once branch November 3, 2026 19:43
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 3, 2026 21:09

This branch was previously deployed

1 inactive deployment
public — 92d35f64 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #9717
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.

1 participant