Skip to content

Make it possible to use rc_context as a decorator. #15303

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
Mar 24, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 19, 2019

See changelog note.

There are also other advantages with contextmanager, e.g. reusing a
context multiple times works

ctx = rc_context(...)
with ctx: ...  # in the context
...  # out of the context
with ctx: ...  # in the context again

(with a test for the decorator form, which is equivalent) but in
practice this will often run into the issue of early/late resolution of
rcParams, so I didn't mention it in the changelog.

xkcd() still needs to be implemented manually in terms of
__enter__/__exit__ but at least we know that creation of the
contextmanager cannot fail, so things are simpler.

Also we don't need to check for whether the backend has been
resolved because rcParams now just prevent re-setting the backend to
auto_backend_sentinel.
(https://github.com/matplotlib/matplotlib/pull/11896/files#diff-9ffb0d1db51a67ee4f37528e00715b3cR852)

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 force-pushed the rc_ctxd branch 3 times, most recently from 1de49b3 to 44b8a4b Compare September 19, 2019 14:02
@ImportanceOfBeingErnest
Copy link
Member

Even with the usage pattern staying the same, is this an API change (rc_context now being a function instead of a class)?

@anntzer
Copy link
Contributor Author

anntzer commented Sep 21, 2019

Well, it's noted as an API change though that specific point is not made explicit; I'm not sure going more into the technical details is going to help legibility of the changelog, but can do so if you insist.

@timhoffm
Copy link
Member

We have never publicly mentioned that rc_context was a class. It looked like a function https://matplotlib.org/api/matplotlib_configuration_api.html#matplotlib.rc_context

So from my point of view, this does not need additional documentation.

@anntzer
Copy link
Contributor Author

anntzer commented Mar 24, 2020

so good to go, then?

@QuLogic
Copy link
Member

QuLogic commented Mar 24, 2020

Yes, but I don't know what's wrong with tests as the link is broken.

See changelog note.

There are also other advantages with contextmanager, e.g. reusing a
context multiple times works

```
ctx = rc_context(...)
with ctx: ...  # in the context
...  # out of the context
with ctx: ...  # in the context again
```

(with a test for the decorator form, which is equivalent) but in
practice this will often run into the issue of early/late resolution of
rcParams, so I didn't mention it in the changelog.

xkcd() still needs to be implemented manually in terms of
`__enter__`/`__exit__` but at least we know that creation of the
contextmanager cannot fail, so things are simpler.

Also we don't need to check for whether the backend has been
resolved because rcParams now just prevent re-setting the backend to
auto_backend_sentinel.
@anntzer
Copy link
Contributor Author

anntzer commented Mar 24, 2020

I rebased and retriggered a build.

@timhoffm timhoffm added this to the v3.3.0 milestone Mar 24, 2020
@timhoffm timhoffm merged commit 63b6312 into matplotlib:master Mar 24, 2020
@anntzer anntzer deleted the rc_ctxd branch March 24, 2020 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants