Skip to content

Conversation

ashwin9390
Copy link
Contributor

@ashwin9390 ashwin9390 commented Jul 10, 2024

When reviewing XAPIPlugin.py for warning fixes,

Bernhard found a superfluous catch and raise in XenAPIPlugin.py's dispatch() function
that we can clean up:

Commmit message:

SystemExit does not need to be caught and raised in this try:
Both other exceptions are subclasses of Exception, so they don't catch SystemExit(BaseException):

By design, SystemExit is a subclass of BaseException and because we are not catching BaseException and also not use a bare except: here, we can cleanup catching and re-raising SystemExit() here.
Reference: https://docs.python.org/3/library/exceptions.html#SystemExit

Author / Signed-off-by: Bernhard Kaindl [email protected]

Committed by: Signed-off-by: Ashwinh [email protected]

In `XenAPIPlugin.py`'s `dispatch()` function, SystemExit does not need to be
caught and raised because both other exceptions are subclasses of Exception:

By design, SystemExit is a subclass of BaseException and because we
are not catching BaseException and also not use a bare `except:`
here, we can cleanup catching and re-raising `SystemExit()` here.

Reference: https://docs.python.org/3/library/exceptions.html#SystemExit

Signed-off-by: Bernhard Kaindl <[email protected]>
Copy link
Collaborator

@bernhardkaindl bernhardkaindl left a comment

Choose a reason for hiding this comment

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

Thanks for opening and reviewing this PR. I wanted to add the reference:

https://docs.python.org/3/library/exceptions.html#SystemExit

Quote:

exception SystemExit
This exception is raised by the sys.exit() function.
It inherits from BaseException instead of Exception so that it is not accidentally caught by code that catches Exception.
This allows the exception to properly propagate up and cause the interpreter to exit.

Hence, as we are not catching BaseException (Failure is also a subclass of Exception) in this try (and we also are not using a bare except:, the SystemExit BaseException will traverse this try without getting chatched. Thus, catching and re-raising it is not needed.

@psafont psafont merged commit 3786289 into xapi-project:feature/py3 Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants