10000 in _axes.py: Added repr to error messages instead of using str by Cloverwave · Pull Request #23383 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

in _axes.py: Added repr to error messages instead of using str #23383

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

Closed
wants to merge 2 commits into from
Closed

in _axes.py: Added repr to error messages instead of using str #23383

wants to merge 2 commits into from

Conversation

Cloverwave
Copy link

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@Cloverwave Cloverwave changed the title Update _axes.py _axes.py: Added repr to error messages instead of using str Jul 2, 2022
@Cloverwave Cloverwave changed the title _axes.py: Added repr to error messages instead of using str in _axes.py: Added repr to error messages instead of using str Jul 2, 2022
@jklymak
Copy link
Member
jklymak commented Jul 2, 2022

Can you provide some context as to why you are doing this? Or maybe mark as draft until you are ready?

raise ValueError(f"{name} must be a single scalar value, "
f"but got {val}")
raise ValueError(f"{repr(name)} must be a single scalar value,"
f" but got {repr(val)}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f" but got {repr(val)}")
f" but got {val!r}")

and so on also works (and is more compact).

f'and width ({width.dtype}) '
f'are incompatible') from e
raise TypeError('the dtypes of parameters x'
f' ({repr(x.dtype)}) '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we want repr here.

@@ -2899,7 +2900,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
"""
if not 1 <= len(args) <= 5:
raise TypeError('stem expected between 1 and 5 positional '
'arguments, got {}'.format(args))
f'arguments, got {repr(args)}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will most likely not produce the expected results.

@@ -3124,7 +3125,8 @@ def get_next_color():

_api.check_isinstance(Number, radius=radius, startangle=startangle)
if radius <= 0:
raise ValueError(f'radius must be a positive number, not {radius}')
raise ValueError('radius must be a positive number, not'
f' {repr(radius)}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense.

@oscargus
Copy link
Member
oscargus commented Jul 4, 2022

I take it that this is related to #21959

However, we do not always want the repr. Typically, for string input it makes sense (as one a) do not have to type the "/' and b) any line breaks or special characters are shown more clearly). But for e.g. a float value or a type it will not make any difference, it will print the same and is just confusing to have the additional call.

@anntzer
Copy link
Contributor
anntzer commented Jul 4, 2022

Agreed with @oscargus; also note that this could/should be spelled {foo!r} instead of {repr(foo)}, for conciseness.

@jklymak
Copy link
Member
jklymak commented Jul 7, 2022

I'm moving to draft until revised. Thanks!

@jklymak jklymak marked this pull request as draft July 7, 2022 08:26
@Cloverwave Cloverwave closed this by deleting the head repository Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0