flax
a648605b - Avoid inadvertent submodule setup

Commit
2 years ago
Avoid inadvertent submodule setup `repr()` is often used as development tool, e.g. by IntelliJ debugger window or in logging. But as it stands, `repr()` causes inadvertent `setup()` of submodules with the following code flow: `repr()` -> `_module_repr()` -> `_attr_repr(submodule)` -> `getattr(submodule, '__name__', None)` (in submodule) -> `__getattr__()` -> `_try_setup()` When using IntelliJ, `repr()` eventually `try_setup()` on a submodule but without proper context. The error is silently eaten in IntelliJ debugger but changes the internal setup state to be DONE and later setup attempt gets ignored, causing failures at a later step. This change will add an additional check in `_attr_repr`. If the input arg `value` is a `Module`, the `'__name__'` attribute will be extracted via `value.__dict__.get` rather than `getattr`, which won't trigger the `getattr` --> `_try_setup()` call. PiperOrigin-RevId: 525340597
Author
Committer
Parents
Loading