Skip to content

Deprecate BoxStyle._Base. - #17737

Merged
timhoffm merged 2 commits into
matplotlib:masterfrom
anntzer:unboxstyle
Oct 11, 2020
Merged

timhoffm merged 2 commits into
matplotlib:masterfrom
anntzer:unboxstyle

Conversation

@anntzer

@anntzer anntzer commented Jun 23, 2020

Copy link
Copy Markdown
Contributor

... by moving the mutation_aspect logic to FancyBboxPatch, so that
boxstyles can be plain classes just implementing __call__ and not
inheriting from anything, which removes the need to inherit from a
private base in userdemo/custom_boxstyle01.py.

A similar approach could be implemented for FancyArrowStyle._Base and
ConnectionStyle._Base.

Closes #13199 (comment).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.4.0 milestone Jun 23, 2020
Comment thread lib/matplotlib/patches.py

def __call__(self, x0, y0, width, height, mutation_size,
aspect_ratio=1.):
return self(self, x0, y0, width, height, mutation_size, 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Won't this fail with the wrong error if __call__ is not overridden, since it no longer takes an aspect_ratio argument?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, but subclasses previously needed to override __call__ to get any meaningful behavior, no? previously not overriding it would result in a NotImplementedError from the base class, now you'd get a TypeError at argument binding time but I think that's close enough?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought they had to override transmute before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I got it wrong just above. Users had to override transmute before, which means that the implementation of _Base.transmute is in facto mostly irrelevant for backcompat purposes. I guess I could even leave it as raising a NotImplementedError? (although I would change the error message, which would be confusing)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, but now nothing calls transmute? So how would existing subclassers find out the deprecation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hum... I guess that in __call__ I can add a call to _deprecate_method_override(__class__.transmute, ...) (and put back the old version of the code under the if transmute := _deprecate_method_override(...) branch)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yea, if that works, sounds good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New version in, but the whole thing's a bit tricky...

Comment thread lib/matplotlib/patches.py Resolved
@anntzer
anntzer force-pushed the unboxstyle branch 3 times, most recently from b109672 to 83f6a53 Compare September 17, 2020 09:35
Comment thread lib/matplotlib/patches.py

def __call__(self, x0, y0, width, height, mutation_size,
aspect_ratio=1.):
return self(self, x0, y0, width, height, mutation_size, 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, but now nothing calls transmute? So how would existing subclassers find out the deprecation?

... by moving the mutation_aspect logic to FancyBboxPatch, so that
boxstyles can be plain classes just implementing `__call__` and not
inheriting from anything, which removes the need to inherit from a
private base in `userdemo/custom_boxstyle01.py`.

A similar approach could be implemented for FancyArrowStyle._Base and
ConnectionStyle._Base.
@QuLogic

QuLogic commented Oct 6, 2020

Copy link
Copy Markdown
Member

If you revert the changes to examples/userdemo/custom_boxstyle01.py, it crashes on draw, instead of warning about the deprecation.

@anntzer

anntzer commented Oct 7, 2020

Copy link
Copy Markdown
Contributor Author

oops, __call__ = transmute should have been cls.__call__ = transmute; fixed.

@timhoffm
timhoffm merged commit 319f35b into matplotlib:master Oct 11, 2020
@anntzer
anntzer deleted the unboxstyle branch October 11, 2020 10:53
@greglucas

Copy link
Copy Markdown
Contributor

@anntzer, I was going through removing 3.4 deprecations and I wasn't entirely clear on what you had planned for the final state here. This looks like it can be removed in main now if you're interested in taking it out though.

@anntzer anntzer mentioned this pull request Jun 10, 2022
6 tasks
@anntzer

anntzer commented Jun 10, 2022 •

Copy link
Copy Markdown
Contributor Author

Done at #23237. Let's discuss it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Examples that use private APIs

4 participants