-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make ExecutableUnavailableError #14776
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
Conversation
lib/matplotlib/__init__.py
Outdated
@@ -283,6 +283,12 @@ def wrapper(): | |||
_ExecInfo = namedtuple("_ExecInfo", "executable version") | |||
|
|||
|
|||
class ExecutableUnavailableError(FileNotFoundError): |
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.
Should this maybe be called ExecutableNotFoundError
in analogy to FileNotFoundError
?
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.
Yeah, that makes sense.
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 guess I went with Unavailable
b/c the motivating case was when an executable convert
is found, but convert --version
returns nonsense.
e4df55a
to
3a9da2a
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.
_get_executable_info is private, so ExecutableNotFoundError should be private too (ie _ExecutableNotFoundError)
@anntzer Not sure about this. I don't think we wrap all usages in a try-catch block. Therefore the ExecutableNotFoundError can rise to the user. In this case it should not be private. |
LGTM. Not going to merge yet, in case anyone else wants to weigh in on the benefits of this. I wasn't really aware that we could define our own errors like this, so am not sure if this is usual in packages... |
@jklymak Refining excpetions by subclassing is a valid practice. See e.g. https://github.com/pandas-dev/pandas/blob/v0.24.2/pandas/errors/__init__.py#L96-L100 and surrounding code. While I don't think one should do it for every exception, it's good if one can make it more specific (and maybe just want to catch that specific one). IMHO that's the case here. |
class ExecutableNotFoundError(FileNotFoundError): | ||
"""Error raised when an executable that Matplotlib optionally | ||
depends on can't be found.""" | ||
pass |
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.
You don't need the "pass" here.
Also the docstring would typically be formatted
"""
Error raised...
"""
(basically either it fits in one line and we write
"""A one line docstring."""
or it doesn't and we write
"""
A multiline
docstring.
"""
or even
"""
One line, but just too long to have opening and closing quotes on the same line.
"""
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.
just tiny formatting stuff
3a9da2a
to
8c31af8
Compare
PR Summary
When checking for executables which are optional dependencies, this makes matplotlib more forgiving of badly-behaved executables. Motivated by #14756, but should be generally helpful.
The new exception (
ExecutableUnavailableError
) inherits fromFileNotFoundError
to ensure that we don't break anyones existing code which usesexcept FileNotFoundError:
to catch this kind of exception.PR Checklist