Skip to content

Deprecate BoxStyle._Base. #17737

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 2 commits into from
Oct 11, 2020
Merged

Deprecate BoxStyle._Base. #17737

merged 2 commits into from
Oct 11, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 23, 2020

... 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

def __call__(self, x0, y0, width, height, mutation_size,
aspect_ratio=1.):
return self(self, x0, y0, width, height, mutation_size, 1)
Copy link
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
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
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
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
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
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
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
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...

@anntzer anntzer force-pushed the unboxstyle branch 3 times, most recently from b109672 to 83f6a53 Compare September 17, 2020 09:35

def __call__(self, x0, y0, width, height, mutation_size,
aspect_ratio=1.):
return self(self, x0, y0, width, height, mutation_size, 1)
Copy link
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
Copy link
Member

QuLogic commented Oct 6, 2020

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

@anntzer
Copy link
Contributor Author

anntzer commented Oct 7, 2020

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
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
Copy link
Contributor Author

anntzer commented Jun 10, 2022

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