10000 Factor out legend/figlegend nargs validation. by anntzer · Pull Request #26189 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Factor out legend/figlegend nargs validation. #26189

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 1 commit into from
Jun 27, 2023
Merged

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Jun 26, 2023

Currently Figure.legend supposedly supports extra_args, forwarding them to the Legend constructor, but because all parameters of the Legend constructor except for the first two have become keyword-only, extra_args actually causes a TypeError to be raised when calling Legend(...) (try e.g. plt.figlegend([], [], "right")). So just don't bother with extra_args anymore, check the case of "more than two positional args" in _parse_legend_args, and also fix test_legend_label_three_args, which was actually hiding the above exception via a mock and not really testing a relevant case anymore.

PR summary

PR checklist

@@ -453,16 +453,8 @@ def test_legend_label_arg(self):
def test_legend_label_three_args(self):
fig, ax = plt.subplots()
lines = ax.plot(range(10))
with mock.patch('matplotlib.legend.Legend') as Legend:
with pytest.raises(Exception):
Copy link
Member

Choose a reason for hiding this comment

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

Should be possible to have an exact exception type (and matching error message)? (And below.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, done

Currently Figure.legend supposedly supports extra_args, forwarding them
to the Legend constructor, but because all parameters of the Legend
constructor except for the first two have become keyword-only,
extra_args actually causes a TypeError to be raised when calling
Legend(...) (try e.g. `plt.figlegend([], [], "right")`).  So just don't
bother with extra_args anymore, check the case of "more than two
positional args" in _parse_legend_args, and also fix
test_legend_label_three_args, which was actually hiding the above
exception via a mock and not really testing a relevant case anymore.
@QuLogic QuLogic merged commit aee2ea3 into matplotlib:main Jun 27, 2023
@QuLogic QuLogic added this to the v3.8.0 milestone Jun 27, 2023
@anntzer anntzer deleted the lav branch June 27, 2023 06:03
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