-
Notifications
You must be signed in to change notification settings - Fork 107
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
Avoid import outside top-level #8295
Conversation
import-outside-top-level (PLC0415)Derived from the Pylint linter. This rule is in preview and is not stable. The What it doesChecks for Why is this bad?PEP 8 recommends placing imports not only at the top-level of a module,
An import statement would typically be placed within a function only to Exampledef print_python_version():
import platform
print(python.python_version()) Use instead: import platform
def print_python_version():
print(python.python_version()) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8295 +/- ##
=======================================
Coverage 90.88% 90.88%
=======================================
Files 347 347
Lines 21076 21076
=======================================
+ Hits 19154 19155 +1
+ Misses 1922 1921 -1 ☔ View full report in Codecov by Sentry. |
8b55d3d
to
02a2d73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -6,6 +6,10 @@ | |||
|
|||
from ert import LibresFacade | |||
from ert.config import CancelPluginException, ErtPlugin | |||
from ert.gui.ertwidgets.customdialog import CustomDialog | |||
from ert.gui.ertwidgets.listeditbox import ListEditBox | |||
from ert.gui.ertwidgets.models.path_model import PathModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I moved these in at some point and it was done for the same reason as
def run_gui_wrapper(args: Namespace, ert_plugin_manager: ErtPluginManager) -> None:
# Importing ert.gui on-demand saves ~0.5 seconds off `from ert import __main__`
from ert.gui.main import run_gui # noqa: PLC0415
When you run ert test_run
, gui will not be imported when you place these imports inside getArguments
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
Keeping as exception at one spot due to circular dependency and one spot due to measurable time-loss to do top-level import.
02a2d73
to
a490506
Compare
Keeping as exception at one spot due to circular dependency and one spot due to measurable time-loss to do top-level import.
Ignoring the issue in script/build, this file is being deleted soon.
Issue
Resolves ruff PLC0415
Approach
fix/add exception/comment.
When applicable