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

style: Fix pylint try-except-raise (W0706) #3997

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

echoix
Copy link
Member

@echoix echoix commented Jul 7, 2024

Do not catch exception only to raise it again

In one file (gui/wxpython/core/utils.py), there was a backport done in 2010 in https://trac.osgeo.org/grass/changeset/41398/ that was supposed to adapt https://trac.osgeo.org/grass/changeset/41396, but with part of the function extracted, having the try in GetListOfLocations is useless, as it is not really used, and will need to get caught elsewhere.

This is part of the effort to introduce Pylint 3.x for #3921

@echoix echoix added this to the 8.5.0 milestone Jul 7, 2024
@echoix echoix requested a review from ninsbl July 7, 2024 23:34
@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python libraries labels Jul 7, 2024
@echoix echoix changed the title python(grass.temporal): Fix pylint try-except-raise (W0706) Jul 7, 2024
@echoix
Copy link
Member Author

echoix commented Jul 7, 2024

In
https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions, it mentions:

  • If an exception occurs during execution of the try clause, the exception may be handled by an except clause. If the exception is not handled by an except clause, the exception is re-raised after the finally clause has been executed.
  • An exception could occur during execution of an except or else clause. Again, the exception is re-raised after the finally clause has been executed.
  • If the finally clause executes a break, continue or return statement, exceptions are not re-raised.
Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@echoix echoix merged commit 4be87a1 into OSGeo:main Jul 9, 2024
26 of 28 checks passed
@echoix echoix deleted the fix-useless-try-except branch July 9, 2024 01:41
a0x8o pushed a commit to a0x8o/grass that referenced this pull request Jul 23, 2024
* python(grass.temporal): Fix pylint try-except-raise (W0706)

Do not catch exception only to raise it again

* gui/wxpython/core/utils: Fix pylint try-except-raise (W0706)

* python: Fix pylint try-except-raise (W0706)

* style: Enable ruff useless-try-except (TRY302) as fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI wxGUI related libraries Python Related code is in Python
2 participants