Skip to content

Conversation

@RhythmP619
Copy link

Enable pylint rule W0611 (unused-import) and clean up code to comply.
Changes:

  • Removed W0611 from disabled rules in pyproject.toml.
  • Fixed unused imports in affected files (2 modules updated).
  • Verified clean state: ran pylint with no W0611 warnings remaining.

@github-actions github-actions bot added Python Related code is in Python libraries tests Related to Test Suite labels Nov 26, 2025
Copy link
Member

@echoix echoix left a 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.

tests.addTests(doctest.DocTestSuite(grid.grid))
tests.addTests(doctest.DocTestSuite(grid.patch))
tests.addTests(doctest.DocTestSuite(grid.split))
# tests.addTests(doctest.DocTestSuite(shortcuts))
Copy link
Member

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>
@echoix
Copy link
Member

echoix commented Dec 3, 2025

How to handle the remaining 1000+ issues in the gui folder?

@petrasovaa
Copy link
Contributor

petrasovaa commented Dec 4, 2025

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.

************* Module doc.examples.gui.wxpython.dialogs
doc/examples/gui/wxpython/dialogs.py:23:0: W0611: Unused import grass (unused-import)
************* Module utils.mkhtml
utils/mkhtml.py:30:4: W0611: Unused grass.script imported as gs (unused-import)
************* Module utils.mkmarkdown
utils/mkmarkdown.py:27:4: W0611: Unused grass.script imported as gs (unused-import)
************* Module gui.wxpython.wxgui
gui/wxpython/wxgui.py:41:4: W0611: Unused wx.lib.agw.advancedsplash imported as SC (unused-import)
************* Module gui.wxpython.vdigit.main
gui/wxpython/vdigit/main.py:18:4: W0611: Unused GV_LINES imported from vdigit.wxdigit (unused-import)
************* Module gui.wxpython.gui_core.wrap
gui/wxpython/gui_core/wrap.py:59:4: W0611: Unused NewIdRef imported from wx as NewId (unused-import)
gui/wxpython/gui_core/wrap.py:61:4: W0611: Unused NewId imported from wx (unused-import)
************* Module gui.wxpython.nviz.main
gui/wxpython/nviz/main.py:23:4: W0611: Unused glcanvas imported from wx (unused-import)
gui/wxpython/nviz/main.py:27:4: W0611: Unused wxnviz imported from nviz (unused-import)
************* Module gui.wxpython.mapwin.decorations
gui/wxpython/mapwin/decorations.py:26:4: W0611: Unused Image imported from PIL (unused-import)
************* Module gui.wxpython.psmap.utils
gui/wxpython/psmap/utils.py:[31](https://github.com/OSGeo/grass/actions/runs/19704457764/job/56448444221?pr=6668#step:27:32):4: W0611: Unused Image imported from PIL as PILImage (unused-import)

@echoix
Copy link
Member

echoix commented Dec 4, 2025

If it’s really only this, sure it’s a good idea to fix these right away

@RhythmP619
Copy link
Author

Hi, sorry for the late reply, I had end-semester exams and just got back to this.
Thanks for checking and for listing the affected files. Since it looks limited to these, I’ll go ahead and fix the unused imports in the GUI and utility modules you mentioned and update the PR shortly.

Copilot AI review requested due to automatic review settings December 15, 2025 11:09
@github-actions github-actions bot added GUI wxGUI related docs labels Dec 15, 2025
Copy link

Copilot AI left a 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.


import vdigit.wxdigit as _wxdigit
IVDigit = _wxdigit.IVDigit
GV_LINES = getattr(_wxdigit, "GV_LINES", -1)
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
GV_LINES = getattr(_wxdigit, "GV_LINES", -1)
GV_LINES = _wxdigit.GV_LINES

Copilot uses AI. Check for mistakes.
@echoix
Copy link
Member

echoix commented Dec 15, 2025

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.

echoix and others added 2 commits December 15, 2025 07:23
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@petrasovaa
Copy link
Contributor

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.

from grass.exceptions import ScriptError

try:
from PIL import Image as PILImage # noqa: F401
Copy link
Member

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)

echoix and others added 3 commits December 26, 2025 13:55
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs GUI wxGUI related libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants