Skip to content

MNT: make signature of GridSpec.update explicit #29956

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
Apr 22, 2025

Conversation

timhoffm
Copy link
Member

Previously, it used **kwargs, because it needs to distinguish between "value not given" and given value is None. A while ago, we have introduced the UNSET sentinel for these cases (in the context of Artist .set()). The PR moves this sentinel to matplotlib._api to make it usable also for gridspec.

Technically, there's an API change here, because the old code raised an AttibuteError for invalid keys. This is now a TypeError by the standards when an invalid keyword argument is used. I consider the old behavior suboptimal as it was not adhereing to standards. I will let the change go without notice because I assume nobody will explicitly catch the exception of an invalid parameter name passed to GridSpec.update().

@timhoffm timhoffm added this to the v3.11.0 milestone Apr 21, 2025
@github-actions github-actions bot added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Apr 21, 2025
@timhoffm timhoffm added Maintenance API: consistency and removed topic: geometry manager LayoutEngine, Constrained layout, Tight layout labels Apr 21, 2025
Comment on lines 20 to +21
from matplotlib import _api, _pylab_helpers, _tight_layout
from matplotlib._api import UNSET as _UNSET
Copy link
Member

Choose a reason for hiding this comment

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

We already have _api imported above, though I guess it makes the signature too long?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the idea is to make the signature more readable, but no strong preference.

Previously, it used **kwargs, because it needs to distinguish between
"value not given" and given value is None. A while ago, we have
introduced the UNSET sentinel for these cases (in the context of Artist
.set()). The PR moves this sentinel to `matplotlib._api` to make it
usable also for gridspec.

Technically, there's an API change here, because the old code raised an
AttibuteError for invalid keys. This is now a TypeError by the standards
when an invalid keyword argument is used. I consider the old behavior
suboptimal as it was not adhereing to standards. I will let the change
go without notice because I assume nobody will explicitly catch the
exception of an invalid parameter name passed to `GridSpec.update()`.
@timhoffm timhoffm force-pushed the mnt-gridspec-update branch from 25983bd to b8673bd Compare April 22, 2025 09:00
@github-actions github-actions bot added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Apr 22, 2025
@jklymak jklymak merged commit 76a47d9 into matplotlib:main Apr 22, 2025
40 checks passed
@timhoffm timhoffm deleted the mnt-gridspec-update branch April 22, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: consistency Maintenance topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants