fix: restore import side effects and eth alias behavior#1074
fix: restore import side effects and eth alias behavior#1074BobTheBuidler merged 8 commits intomasterfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 298951bb57
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
dank_mids/eth.py
Outdated
| try: | ||
| dank_eth = parent.dank_eth | ||
| except Exception: | ||
| if getattr(parent, "eth", None) is sys.modules.get(__name__): |
There was a problem hiding this comment.
Avoid resolving
eth while cleaning up failed alias restore
When dank_mids.eth is imported in an environment where dank_mids.dank_eth cannot be resolved (e.g., Brownie not connected), this getattr(parent, "eth", None) call triggers the module alias guard in dank_mids.__init__, which re-enters lazy alias resolution and raises BrownieNotConnectedError. That exception escapes _restore_eth_alias() and makes import dank_mids.eth fail, even though the submodule itself is otherwise importable. The cleanup path should read the raw module dict (or catch this access) instead of invoking attribute resolution again.
Useful? React with 👍 / 👎.
|
Good catch — fixed by reading |
Summary
dank_midsanddank_mids.helperswhile keeping helper symbols lazy.eth/web3alias resolution when thedank_mids.ethsubmodule is imported first.Rationale
dank_mids.ethalways resolving to the instance (or raisingBrownieNotConnectedError).Details
_ensure_side_effects()at module import indank_mids/__init__.pyanddank_mids/helpers/__init__.py.eth/web3when submodule shadowing occurs.dank_mids.ethalias whendank_mids.ethloads.PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest tests/unit/test_lazy_imports.py.