Repository navigation
[Backport] PR #7646 to release/3.0.0 - #7720
Conversation
`isaaclab/utils/__init__.py` attaches its exports lazily from
`__init__.pyi`. One of those exports,
`configclass`, has the same name as the sub-module that defines it,
`isaaclab.utils.configclass`.
Whenever that sub-module is imported, the import machinery binds the
module object onto
`isaaclab.utils`, which shadows the lazily attached decorator. From that
point on:
```python
from isaaclab.utils import configclass # -> <module 'isaaclab.utils.configclass'>
@configclass
class MyCfg:
value: int = 1
```
Which object the name resolves to depends only on which of the two was
imported first, so downstream
code breaks without ever importing the sub-module itself. Importing
`isaaclab_rl`, `isaaclab_newton`,
`isaaclab_contrib` or `isaaclab_teleop` is enough, since they all use
`from isaaclab.utils.configclass import configclass` internally:
```python
from isaaclab_rl.rsl_rl import RslRlOnPolicyRunnerCfg
from isaaclab.utils import configclass # now a module
@configclass
class MyAgentCfg: # TypeError: 'module' object is not callable
...
```
`configclass` is a documented export of `isaaclab.utils` —
`docs/source/api/lab/isaaclab.utils.rst`
lists it under the module's *Functions* rubric — and this is the import
form Isaac Lab 1.x/2.x code
uses, so downstream projects hit this while porting to 3.0 and have to
rewrite every `configclass`
import. `lazy_loader` guards against this collision, but only when the
attribute happens to be
resolved before the sub-module is imported, so the mitigation is
order-dependent.
The mirror image is broken today too: resolving the decorator first
makes `lazy_loader` write it
into the package `__dict__`, after which the sub-module is unreachable
as an attribute of
`isaaclab.utils` — `import isaaclab.utils.configclass as m` binds the
function, and
`isaaclab.utils.configclass._field_module_dir` raises `AttributeError`.
One attribute slot cannot
hold two objects, so whichever import runs first wins and the other form
breaks.
This PR makes them one object. `isaaclab.utils.configclass` gets a
`ModuleType` subclass that
forwards `__call__` to the decorator, and `isaaclab.utils.__getattr__`
always hands out that
sub-module rather than letting `lazy_loader` cache the bare function.
The attribute is then the same
object regardless of import order, and it is both a module and callable,
so the decorator, aliased
imports, dotted attribute access, `from isaaclab.utils.configclass
import ...`,
`importlib.import_module`, `mock.patch` and `string_to_callable` all
work in either order. Nothing
that works on `develop` stops working, so no migration is required.
`configclass` is currently the only name in the repository where a
`.pyi` stub export collides with a
sibling sub-module of the same name, so nothing else changes behaviour.
Fixes # (issue)
- Bug fix (non-breaking change which fixes an issue)
- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`
- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
---------
Signed-off-by: Kelly Guo <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Kelly Guo <[email protected]>
(cherry picked from commit f023d8c)
|
Too many files changed for review (535 files, 100 file limit). |
|
run-ci |
There was a problem hiding this comment.
Isaac Lab Review Bot
The backport consistently routes configclass imports through isaaclab.utils and resolves the module-versus-decorator shadowing by making the submodule callable. One API compatibility gap remains: the callable-module shim does not preserve the decorator function's keyword-argument contract.
- Design and architecture: Using a callable
isaaclab.utils.configclassmodule provides import-order-independent behavior while retaining access to submodule members. However, the module wrapper must fully delegate the existing callable interface rather than expose a narrower call signature. - API: The underlying public function accepts
configclass(cls, **kwargs)and forwards options todataclass, but_CallableModule.__call__accepts onlycls. Consequently, the newly recommendedfrom isaaclab.utils import configclasspath rejects valid calls such asconfigclass(MyCfg, kw_only=True). Forward*argsand**kwargsto the underlying function. - Implementation: The fresh-interpreter regression test verifies both import orders, bare decorator use, and submodule member access, but it does not exercise decorator keyword arguments. Extend the callable shim and test coverage to preserve that existing behavior.
Minor fixes needed. Posted 1 actionable finding inline.
Automated review; human maintainers own approval decisions.
| ``import isaaclab.utils.configclass as ...`` and dotted attribute access. | ||
| """ | ||
|
|
||
| def __call__(self, cls: type) -> type: |
There was a problem hiding this comment.
🟡 Warning · Api — Callable module drops configclass keyword arguments
configclass(cls, **kwargs) documents forwarding extra arguments to dataclass, and isaaclab/utils/__init__.pyi still exports it as that function. After this change from isaaclab.utils import configclass yields the module, whose __call__ accepts only cls, so configclass(MyCfg, kw_only=True) raises TypeError on the very import path this PR migrated all call sites to. Accept and forward *args, **kwargs.
Backports #7646 to
release/3.0.0.The original cherry-pick conflicted. An NVIDIA inference model proposed this resolution, and deterministic validation confirmed that it changes no paths outside the original PR. Because conflict resolution cannot be certified as an exact patch replay, this PR is intentionally a draft and requires release-maintainer review.
f023d8c5e386c1b05a233e437ad524633c16d1de130c7f1e16220cf200896b3cda031790e446fcdebfecc63d0c29f410d1b78caf60f8c3159a002656