Skip to content

Navigation Menu

Sign in
Appearance settings

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: if we have already subclassed mixin class just return #20403

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
Jun 10, 2021

Conversation

tacaswell
Copy link
Member

PR Summary

If subplot_class_factory is passed a base class that already sub-classes
the mixin class, simply return the base class.

This will allow third-party packages to derive from maxes.Subplot rather
than maxes.Axes which will allow easier (by ensuring that our classes
and the third-party classes do not mix in the mro).

This allows a fix to proplot-dev/proplot#248 by changing which mpl class they inherit from (which brings them closer inline with the mpl36 goal of merging the subplot logic fulling into Axes

Currently we have:

# class CartesianAxes(maxes.Axes)
In [10]: matplotlib.axes.subplot_class_factory(proplot.axes.CartesianAxes).mro()
Out[10]: 
[matplotlib.axes._subplots.CartesianAxesSubplot,
 matplotlib.axes._subplots.SubplotBase,
 proplot.axes.cartesian.CartesianAxes,
 proplot.axes.base.Axes,
 matplotlib.axes._axes.Axes,
 matplotlib.axes._base._AxesBase,
 matplotlib.artist.Artist,
 object]
```

with this PR + changing the inheritance in proplot we have: 

```
# class CartesianAxes(maxes.Subplot)
In [4]: matplotlib.axes.subplot_class_factory(proplot.axes.CartesianAxes).mro()
Out[4]: 
[proplot.axes.cartesian.CartesianAxes,
 proplot.axes.base.Axes,
 matplotlib.axes._subplots.AxesSubplot,
 matplotlib.axes._subplots.SubplotBase,
 matplotlib.axes._axes.Axes,
 matplotlib.axes._base._AxesBase,
 matplotlib.artist.Artist,
 object]

The key detail is that in the first case the resoltion order bounces through mpl -> proplot -> mpl which means the code above / below supre().__init__(...) calls gets interleaved between the two code bases. This means that when the call to super().__init__() returns in the proplot code they can not assume that the Axes is fully initialized (because any code that runs after the super() on the mpl side may will not have run yet becaues it will run after the proplot __init__ returns). In the second case all of the proplot classes are before all of our classes so that if proplot does super().__init__(...) they can assume that the object is in a, from mpl's point of view, fully initialized and consistent state.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

If subplot_class_factory is passed a base class that already sub-classes
the mixin class, simply return the base class.

This will allow third-party packages to derive from maxes.Subplot rather
than maxes.Axes which will allow easier (by ensuring that our classes
and the third-party classes do not mix in the mro).
@jklymak
Copy link
Member

jklymak commented Jun 10, 2021

Feel free to self merge. I'm not sure if this needs a back port...

@tacaswell
Copy link
Member Author

I would like to backport this to give proplot an easy path to un-breaking with the 3.4 series.

@tacaswell tacaswell merged commit bd79d5d into matplotlib:master Jun 10, 2021
@tacaswell tacaswell deleted the noop_subplot_class_factory branch June 10, 2021 16:14
@lumberbot-app
Copy link

lumberbot-app bot commented Jun 10, 2021

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.4.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 bd79d5df8b4d4b9180792953339aa8eda8e9d068
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #20403: FIX: if we have already subclassed mixin class just return'
  1. Push to a named branch :
git push YOURFORK v3.4.x:auto-backport-of-pr-20403-on-v3.4.x
  1. Create a PR against branch v3.4.x, I would have named this PR:

"Backport PR #20403 on branch v3.4.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Jun 10, 2021
…n class just return

Merge pull request matplotlib#20403 from tacaswell/noop_subplot_class_factory

FIX: if we have already subclassed mixin class just return

Conflicts:
	lib/matplotlib/cbook/__init__.py
          - logic is in axes/_subplots.py on this branch
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.

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