-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[ENH]: Use repr instead of str in the error message #21959
Copy link
Copy link
Closed
Labels
Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!New feature
Milestone
Description
Problem
I mistakenly supplied "blue\n" as the argument c for matplotlib.axes.Axes.scatter , then matplitlib claimed for illegal color name like this:
ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not blue
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:
raise ValueError(
f"'c' argument must be a color, a sequence of colors, "
f"or a sequence of numbers, not {c!r}") from so that we may now get an easy-to-troubleshoot error like this:
ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not "blue\n"
This kind of improvement can be applied to many other places.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!New feature