FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[ENH]: Use `repr` instead of `str` in the error message · Issue #21959 · matplotlib/matplotlib · GitHub

Repository navigation

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

Closed

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.

Activity

  1. added this to the v3.6.0 milestone on Dec 15, 2021
  2. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Dec 15, 2021
  3. tacaswell commented on Dec 15, 2021

    Member

    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!).

  4. tacaswell commented on Dec 15, 2021

    Member

    @e5f6bd If you are interested in opening a PR with this change, please have at it!

  5. e5f6bd commented on Dec 15, 2021

    Author

    @e5f6bd Thanks, but I'm a bit busy recently, so I'll leave this chance to someone else.

  6. Hashcode-Ankit commented on Dec 29, 2021

    If this issue has not been resolved yet and nobody working on it I would like to try it

  7. story645 commented on Dec 29, 2021

    Member

    Looks like #21968 is addressing this issue

  8. Hashcode-Ankit commented on Dec 29, 2021

    yeah but the issue still open

  9. Cloverwave commented on Jul 1, 2022

    Working on this now in axes_.py,
    future plans to work on this in all files with error raising.

  10. Cloverwave commented on Jul 1, 2022

    Also converting f strings to template strings where I see them in raised errors

  11. oscargus commented on Jul 4, 2022

    Member

    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.

  12. modified the milestones: v3.6.0, v3.7.0 on Aug 24, 2022
  13. added 3 commits that reference this issue on Nov 8, 2022
    7ec1c0a
    6f1ece0
    ffb91b3
  14. added a commit that references this issue on Nov 10, 2022
    04ce3e9
  15. added a commit that references this issue on Dec 19, 2022
    547460f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL