Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace relative imports for imports outside of the immediate module #1738

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

jamesbiggs
Copy link
Collaborator

Following a discussion on the developer catch-up, we decided it would be good practice to only use relative imports within the immediate module, e.g.

in etna.articles.blocks.py, this is fine:
from .models import ArticlePage

but we shouldn't use them like this:
from ..media.blocks import MediaBlock

and should instead be writing:
from etna.media.blocks import MediaBlock

It adds unnecessary additional cognitive load. The two apps are not immediately related to one another - etna.media can exist without etna.articles (in theory). So there is a chance that the path may change. It also makes it easier to trace where you are importing things from, and makes it clear to a developer trying to understand your code.

"Explicit is better than implicit."

@jamesbiggs jamesbiggs enabled auto-merge (squash) October 30, 2024 13:58
@jamesbiggs jamesbiggs merged commit 99225cb into develop Oct 30, 2024
7 checks passed
@jamesbiggs jamesbiggs deleted the chore/absolute-imports branch October 30, 2024 14:09
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.

2 participants