Skip to content

fix: restore import side effects and eth alias behavior#1074

Merged
BobTheBuidler merged 8 commits intomasterfrom
fix/restore-import-side-effects-20260216
Feb 16, 2026
Merged

fix: restore import side effects and eth alias behavior#1074
BobTheBuidler merged 8 commits intomasterfrom
fix/restore-import-side-effects-20260216

Conversation

@BobTheBuidler
Copy link
Owner

Summary

  • Restore import-time side effects for dank_mids and dank_mids.helpers while keeping helper symbols lazy.
  • Guard eth/web3 alias resolution when the dank_mids.eth submodule is imported first.
  • Update lazy-import tests to assert immediate side effects and alias behavior.

Rationale

Details

  • Call _ensure_side_effects() at module import in dank_mids/__init__.py and dank_mids/helpers/__init__.py.
  • Install a module alias guard to re-resolve eth/web3 when submodule shadowing occurs.
  • Restore the parent dank_mids.eth alias when dank_mids.eth loads.
  • Tests: PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest tests/unit/test_lazy_imports.py.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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__):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@BobTheBuidler
Copy link
Owner Author

Good catch — fixed by reading parent.__dict__ directly so alias cleanup no longer triggers lazy resolution. Updated in 53fc78d and tests still pass.

@BobTheBuidler BobTheBuidler merged commit cdcf8e3 into master Feb 16, 2026
@BobTheBuidler BobTheBuidler deleted the fix/restore-import-side-effects-20260216 branch February 16, 2026 18:53
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