-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[ENH]: Use repr
instead of str
in the error message
#21959
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
Comments
Labeling this as a good first issue as this is a straight forward change that should not bring up any API design issues (yes technically changing the wording of an error message may break someone, but that is so brittle I am not going to worry about that). Will need a test (the new line example is a good one!). |
@e5f6bd If you are interested in opening a PR with this change, please have at it! |
@e5f6bd Thanks, but I'm a bit busy recently, so I'll leave this chance to someone else. |
If this issue has not been resolved yet and nobody working on it I would like to try it |
Looks like #21968 is addressing this issue |
yeah but the issue still open |
In case of ValueError caused by user given input, raw string will be displayed in Error Message.
Now in case of ValueError caused by user defined input, raw string will be shown in the error message.
Working on this now in axes_.py, |
Also converting f strings to template strings where I see them in raised errors |
f-string are usually preferred due to speed issues. Which is not critical, but if one can choose, f-strings are not worse. |
* use repr in error message closes matplotlib#21959 * add test for repr error message * fix formatting * clean up formatting and naming * add `pragma: no cover` * remove import and function name a bit more explicit
Problem
I mistakenly supplied
"blue\n"
as the argumentc
formatplotlib.axes.Axes.scatter
, thenmatplitlib
claimed for illegal color name like this:I was not aware that the argument actually contained a trailing newline so I was very confused.
Proposed solution
The error message would be nicer if it outputs user's input via
repr
.For example, in this case the error message here can be easily replced with:
so that we may now get an easy-to-troubleshoot error like this:
This kind of improvement can be applied to many other places.
The text was updated successfully, but these errors were encountered: