Skip to content

More granular imports #4271

@bhashemian

Description

@bhashemian

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:

from monai.utils import InterpolateMode, deprecated_arg, ensure_tuple, ensure_tuple_rep, min_version, optional_import
from monai.utils.enums import PostFix

and a better way to import would be:

from monai.utils.deprecate_utils import deprecated_arg
from monai.utils.enums import InterpolateMode, PostFix
from monai.utils.misc import ensure_tuple, ensure_tuple_rep
from monai.utils.module import min_version, optional_import

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions