Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix argument types in examples and tests #28764

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from

Conversation

oscargus
Copy link
Member

PR summary

Not sure if this is wanted, so I have only done this for a few methods as a discussion opener.

Background: I got a typing error in my editor when looking at an example.

It seems to me that if we type something as a tuple (and not as a tuple or a list), it makes sense to provide a tuple in all examples (and tests as I did some search-and-replace). But then I do not know the background to typing it as a tuple only.

PR checklist

doc/users/prev_whats_new/dflt_style_changes.rst Outdated Show resolved Hide resolved
@@ -509,7 +509,7 @@ def test_invalid_figure_add_axes():
fig.add_axes((.1, .1, .5, np.nan))

with pytest.raises(TypeError, match="multiple values for argument 'rect'"):
fig.add_axes([0, 0, 1, 1], rect=[0, 0, 1, 1])
fig.add_axes((0, 0, 1, 1), rect=[0, 0, 1, 1])
Copy link
Member

Choose a reason for hiding this comment

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

rect should also be a tuple, though I'm surprised you don't get a type error for invalid parameters here (though that's on purpose and should be ignored.)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is because I identify one type of error and then do regex-based search and replace for that on all files.

lib/matplotlib/tests/test_lines.py Outdated Show resolved Hide resolved
@@ -168,7 +168,7 @@ def test_rotation():
mpl.rcParams['text.usetex'] = True

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax = fig.add_axes((0, 0, 1, 1))
ax.set(xlim=[-0.5, 5], xticks=[], ylim=[-0.5, 3], yticks=[], frame_on=False)
Copy link
Member

Choose a reason for hiding this comment

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

ax.set probably won't type check, but for consistency, xlim and ylim here should also be tuples.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

I approve, subject to addressing @QuLogic's comments.

@oscargus
Copy link
Member Author

Will sort the comments out and over time find and fix more if this type when bored.

@rcomer
Copy link
Member

rcomer commented Sep 7, 2024

I take the liberty of putting this one in draft since it seems to be contingent on @oscargus' boredom levels.

@rcomer rcomer marked this pull request as draft September 7, 2024 11:58
@ksunden
Copy link
Member

ksunden commented Sep 7, 2024

I am also in favor of these changes, of course lists work, but don't allow you to specify length, which is why the type hints are Tuple... since the number of elements is super important for these cases

@QuLogic
Copy link
Member

QuLogic commented Apr 16, 2025

I took the liberty to rebase and fix the commented issues.

@QuLogic QuLogic marked this pull request as ready for review April 16, 2025 23:48
@QuLogic QuLogic added this to the v3.11.0 milestone Apr 16, 2025
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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.