zuko icon indicating copy to clipboard operation
zuko copied to clipboard

Remove star imports from init modules

Open MArpogaus opened this issue 1 year ago • 1 comments

Description

Hello @francois-rozet,

This should take up our discussion on the usage of star imports in #38:

Using star imports in Python is very convenient and saves you from typing long module names repeatedly if you need to use multiple entities from a module. However, from my experience, star imports can cause naming conflicts if two modules have entities with the same name. Importing everything from a module can make it difficult to determine which specific entities are being used in the code. This can make code more error-prone and harder to debug. Additionally, Linters like ruff cant warn you about unused imports when start imports are used.

Hence, I would suggest removing them from the init modules for the reasons mentioned above, at the cost of slightly higher maintenance.

Implementation

I did originally eliminate the use of all start import in commit 08d3f43. If desired, I could cherry-pick zuko/flows/__init__.py from commit 08d3f43 and remove the ignores from pyprojetc.toml in a new PR.

Alternatives

Leave everything as it is now.

MArpogaus avatar Feb 01 '24 13:02 MArpogaus

I agree to disable star imports in __init__.py files as it would prevent components (flows) with the same name to exist. However, we should still ignore F401. Linters will still detect "overriden" imports, even if they are not used.

francois-rozet avatar Feb 01 '24 14:02 francois-rozet

Addressed in 7c05693058d41fc747101660171ac7702cdea109.

francois-rozet avatar Jun 06 '24 14:06 francois-rozet