More granular imports #4274
Replies: 4 comments
-
I'm not sure this will fix circular import issues, if you import |
Beta Was this translation helpful? Give feedback.
-
so this is mostly style preference, unless we have automatic tools to enforce this, it's not easy to implement. I'm converting it to a discussion. |
Beta Was this translation helpful? Give feedback.
-
I'm not aware of tools that will refactor imports for us like that, isort just does sorting. I can see it being implementing using refactoring tools like rope but that would be a script we'd have to write. |
Beta Was this translation helpful? Give feedback.
-
Some codes in MONAI import many components from the parent modules (look at example below). This is generally fine but can increase the chance of circular import in MONAI core. Although we should avoid such situations with some tricks like deferred imports, it would be a good practice to import the modules with more granularity in the core MONAI.
This is an example of what we can see in MONAI:
and a better way to import would be:
The changes are small and easy per each file but there are more than 200 instances of this kind of imports, which makes it a tedious task to improve. I suggest to look for this imports in any PR review and gradually fix the previous ones.
Beta Was this translation helpful? Give feedback.
All reactions