Skip to content

[ENH]: Use repr instead of str in the error message #21959

Closed
@e5f6bd

Description

@e5f6bd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good first issueOpen a pull request against these issues if there are no active ones!New feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions