-
-
Notifications
You must be signed in to change notification settings - Fork 391
style: enable unused import pylint rule (W0611) and fix resulting violations #6668
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
base: main
Are you sure you want to change the base?
Conversation
echoix
left a comment
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.
Great work! Glad you found an easy one. I’m checking here with others about the underlying problems.
python/grass/pygrass/modules/grid/testsuite/test_pygrass_modules_grid_doctests.py
Show resolved
Hide resolved
| tests.addTests(doctest.DocTestSuite(grid.grid)) | ||
| tests.addTests(doctest.DocTestSuite(grid.patch)) | ||
| tests.addTests(doctest.DocTestSuite(grid.split)) | ||
| # tests.addTests(doctest.DocTestSuite(shortcuts)) |
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.
Again, what is the shortcuts? It’s the source of the unused imports
…es_grid_doctests.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
How to handle the remaining 1000+ issues in the gui folder? |
I am not sure I fully understand the output, but I think it's just 9 files, we could fix those. |
|
If it’s really only this, sure it’s a good idea to fix these right away |
|
Hi, sorry for the late reply, I had end-semester exams and just got back to this. |
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.
Pull request overview
This PR enables the pylint rule W0611 (unused-import) and removes or refactors imports that were flagged as unused. The changes affect 11 files across utilities, Python modules, and GUI components.
Key changes:
- Removed W0611 from disabled pylint rules in pyproject.toml
- Removed truly unused imports from 6 files (utilities and test modules)
- Refactored 3 files to use runtime checks instead of imports (PIL availability checks, vdigit imports)
- Removed conditional wx.NewId import from gui_core/wrap.py
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Removed W0611 from disabled pylint rules to enforce unused import checking |
| utils/mkmarkdown.py | Removed unused conditional grass.script import |
| utils/mkhtml.py | Removed unused conditional grass.script import |
| python/grass/pygrass/modules/testsuite/test_pygrass_modules_doctests.py | Removed unused shortcuts import from module imports |
| python/grass/pygrass/modules/grid/testsuite/test_pygrass_modules_grid_doctests.py | Removed unused grass.pygrass.modules import |
| gui/wxpython/wxgui.py | Removed unused wx.lib.agw.advancedsplash conditional import |
| gui/wxpython/vdigit/main.py | Refactored imports to avoid unused-import warning while re-exporting symbols |
| gui/wxpython/psmap/utils.py | Replaced PIL import with importlib.util.find_spec check for availability |
| gui/wxpython/nviz/main.py | Removed unused wx.glcanvas and nviz.wxnviz imports |
| gui/wxpython/mapwin/decorations.py | Replaced PIL import with importlib.util.find_spec check for availability |
| gui/wxpython/gui_core/wrap.py | Removed conditional NewId import (breaks module API - see critical issue) |
| doc/examples/gui/wxpython/dialogs.py | Removed redundant grass import (gettext setup handled by core.globalvar) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gui/wxpython/vdigit/main.py
Outdated
|
|
||
| import vdigit.wxdigit as _wxdigit | ||
| IVDigit = _wxdigit.IVDigit | ||
| GV_LINES = getattr(_wxdigit, "GV_LINES", -1) |
Copilot
AI
Dec 15, 2025
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.
The refactored import pattern changes behavior subtly. Previously, if GV_LINES didn't exist in the wxdigit module, an ImportError would be raised during the import statement. Now, getattr provides a default value of -1 if GV_LINES doesn't exist. This could mask issues where GV_LINES is expected to be present but isn't, allowing code to proceed with an incorrect default value rather than failing early. Consider whether this fallback behavior is intentional or if GV_LINES should always be present when the import succeeds.
| GV_LINES = getattr(_wxdigit, "GV_LINES", -1) | |
| GV_LINES = _wxdigit.GV_LINES |
Co-authored-by: Copilot <[email protected]>
|
We already decided that when needed, we can assume that wxPhoenix is always present. The transition period is done. We don't need to make it work for the old, pre-v4 wxPython. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
For some of these, specifically nviz and vdigit import I would rather use a per-file ignore rather than changing it, the import pattern is clear and I am afraid we will break something with whatever other solution there is. |
… keep original code
| from grass.exceptions import ScriptError | ||
|
|
||
| try: | ||
| from PIL import Image as PILImage # noqa: F401 |
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.
Can you make sure that other files needing PILImage are still working correctly? It seems some were importing from psmap.utils (not really good practice, but it's there now)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Enable pylint rule W0611 (unused-import) and clean up code to comply.
Changes: