Skip to content

fix(imports): remove dunder init#1545

Open
paul-nechifor wants to merge 2 commits intodevfrom
paul/fix/remove-dunder-inits
Open

fix(imports): remove dunder init#1545
paul-nechifor wants to merge 2 commits intodevfrom
paul/fix/remove-dunder-inits

Conversation

@paul-nechifor
Copy link
Contributor

@paul-nechifor paul-nechifor commented Mar 13, 2026

Problem

  • We have a lot of __init__.py files which aggregate imports. This causes us to waste time importing things we don't need. Jeff has merged a solution to this ( Import Fix & Optimize: G1 without ROS, lazy imports, Fix bad dir naming, DIM-457, DIM-458, DIM-460, DIM-461 #1221 ), but I don't see why we need to bother re-exporting things to begin with. It's so much easier to import from the source.

  • What bugs me is that when we re-export, we end up with two (or more) paths from which we can import the same thing. The codebase has this a lot.

  • You always have to double check what you're importing. This occurs when a re-export shadows a module with a function within it. For example imagine you have def foo in dimos/core/foo.py. You use foo(…) in your code and you have to import it. Which import do you add? from dimos.core import foo or from dimos.core.foo import foo. The second is always reliable. But the first depends on whether dimos/core/__init__.py re-exports def foo. If it does not, then from dimos.core import foo is still valid, but it's not the function, it's the module. Allowing re-exports leads to uncertainty.

  • If the worry is that removing them creates long imports for users, then there is a solution for this. We can create a single file of lazy imports at the root defining our entire public API. But internally, we should just import things from where they are defined.

Closes DIM-534

Solution

  • Remove all __init__.py files.
  • Fix all the imports to import from the source.
  • Add a test to make sure new __init__.py files aren't added again.

Breaking Changes

  • You have to import from the source now.

How to Test

...

Contributor License Agreement

  • I have read and approved the CLA.

@paul-nechifor paul-nechifor force-pushed the paul/fix/remove-dunder-inits branch from e4f2b1f to 4016074 Compare March 13, 2026 23:23
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