Skip to content

Delete all dunder init files #1547

@dimos-bot

Description

@dimos-bot

Issue

  • 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.

Synced from DIM-534

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions