Skip to content

Use repr in error message Addresses #21959 #24403

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

Merged
merged 6 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4416,7 +4416,7 @@ def invalid_shape_exception(csize, xsize):
# severe failure => one may appreciate a verbose feedback.
raise ValueError(
f"'c' argument must be a color, a sequence of colors, "
f"or a sequence of numbers, not {c}") from err
f"or a sequence of numbers, not {c!r}") from err
else:
if len(colors) not in (0, 1, xsize):
# NB: remember that a single color is also acceptable.
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8290,3 +8290,17 @@ def test_extent_units():
with pytest.raises(ValueError,
match="set_extent did not consume all of the kwargs"):
im.set_extent([2, 12, date_first, date_last], clip=False)


def test_scatter_color_repr_error():

def get_next_color():
return 'blue' # pragma: no cover
msg = (
r"'c' argument must be a color, a sequence of colors"
r", or a sequence of numbers, not 'red\\n'"
)
with pytest.raises(ValueError, match=msg):
c = 'red\n'
mpl.axes.Axes._parse_scatter_color_args(
c, None, kwargs={}, xsize=2, get_next_color_func=get_next_color)