Shorten various offsetbox implementations
PR Summary
1st commit: Inherit OffsetBox.{get_offset,get_window_extent}.
By making the parameters of OffsetBox.get_offset optional (which matches the fact that there are currently subclasses for which get_offset does not take any parameters), and adjusting OffsetBox.get_window_extent to use get_extent (which is typically redefined in subclasses) instead of get_extent_offsets (which is not), we can inherit the implementation of OffsetBox.get_window_extent across most subclasses instead of having to copy-paste it again and again.
2nd commit: Inline AnchoredOffsetBox._update_offset_func.
It is only called in get_window_extent -- and in draw, but that
call is immediately followed by a call to get_window_extent, so it is
redundant.
PR Checklist
Tests and Styling
- [ ] Has pytest style unit tests (and
pytestpasses). - [ ] Is Flake 8 compliant (install
flake8-docstringsand runflake8 --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).
I agree the API is pretty confusing, but that's what it was before. Still, it can be improved (last commit now) by making the callables passed to set_offset take no arguments whatsoever (they can call get_extent themselves), and therefore make get_offset also take no arguments. For backcompat I maintained the ability to pass *args, **kwargs if the callable passed to set_offset likewise takes such parameters (and likewise maintained in the AnchoredOffsetbox offset computer), but this can be deprecated in a later step.
Making args to get_offset explicit makes everything much more complicated, because now I need to check the signature of self._offset (if it is a callable) to decide whether to pass args or not (even if you make the signature width=None, ... you cannot know whether the called did get_offset() or get_offset(None, ...) (which could be technically valid with whatever offset func they set previously).
Likewise, making the docstring of set_offset more restrictive actually seems more confusing, as you'd now need to explicitly state the "old" signature which is something we want to get rid of.
I have no qualms with deprecating the old set_offset form but again don't think it has to be done as part of this PR (which breaks no backcompat whatsoever, AFAICT).
Done (with minor rewordings on top of the proposed docs).
@tacaswell has told me that the message makes sense from the contents, but that last commit message is a bit inscrutable at first glance.
Agreed, is the new title better? :)
This behavior / signature goes back to 3ae92215dae8f55903f6bc6c8c063e5cb7498bac which is related to mouse-draggable artists.
I do not feel I understand why it was there to begin with to be confident ripping it out.
Moved to draft. Seems to at least need an Api note, and response to comments above
Superseded by #23896 and #23907.