Skip to content

Don't revalidate original rcParams when exiting rc_context. #8962

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
Jul 31, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 30, 2017

  • Rewrite rc_context using contextmanager, which removes the need for
    saving state.

  • When __exit__ing rc_context, skip rcParam validation, as the items
    have already been validated originally.

The rationale for not revalidating (beyond a minor gain in speed) is
that it may make sense to smuggle seemingly "invalid" values into the
rcParams (by calling dict.__setitem__), and we do not want them to
cause an error when exiting a rc_context (of course, they may or may not
cause an error at the backend level, but that is the responsibility of
whoever set this "invalid" value).

For example, the rcparam lines.antialiased is declared as a boolean,
but the mpl_cairo backend actually also recognizes any of cairo's
internal antialiasing enum values (NONE, FAST, GOOD, BEST, etc.).

(The rst docs needed to be slightly updated because .. autoclass::
rc_context won't work anymore, so I also took advantage of that to
reorder all the rc-related functions slightly more logically.)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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_context branch 2 times, most recently from cf42412 to f7134f2 Compare July 30, 2017 09:46
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

conditional on the doc-building being fixed.

Minor API change in that chain is no longer available in the mpl namespace, but people should not be using that anyway!

.. autofunction::rcdefaults

.. autofunction::rc_file
.. autodata:: rc_context
Copy link
Member

Choose a reason for hiding this comment

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

autodata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See http://www.sphinx-doc.org/en/stable/ext/autodoc.html?highlight=autodata#directive-autofunction, but I guess this technically still qualifies as a function.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 30, 2017

Looks like s-g fails to resolve https://docs.{numpy,scipy}.org/doc/numpy/reference/searchindex.js which indeed do not exist. Not sure whether they used to exist and numpy/scipy changed their docs build? (the issue also appears with s-g 0.1.11 so it's not due to the s-g update)

@QuLogic
Copy link
Member

QuLogic commented Jul 30, 2017

You'll need to rebase against #8955 (or just latest master).

anntzer added 2 commits July 30, 2017 15:43
- Rewrite rc_context using contextmanager, which removes the need for
  saving state.

- When `__exit__`ing rc_context, skip rcParam validation, as the items
  have already been validated originally.

The rationale for not revalidating (beyond a minor gain in speed) is
that it may make sense to smuggle seemingly "invalid" values into the
rcParams (by calling `dict.__setitem__`), and we do not want them to
cause an error when exiting a rc_context (of course, they may or may not
cause an error at the backend level, but that is the responsibility of
whoever set this "invalid" value).

For example, the rcparam `lines.antialiased` is declared as a boolean,
but the mpl_cairo backend actually also recognizes any of cairo's
internal antialiasing enum values (NONE, FAST, GOOD, BEST, etc.).

(The rst docs needed to be slightly updated because .. autoclass::
rc_context won't work anymore, so I also took advantage of that to
reorder all the rc-related functions slightly more logically.)
@anntzer
Copy link
Contributor Author

anntzer commented Jul 30, 2017

thanks, done

@QuLogic QuLogic added this to the 2.1 (next point release) milestone Jul 31, 2017
@QuLogic QuLogic merged commit c4d7ce4 into matplotlib:master Jul 31, 2017
@anntzer anntzer deleted the rc_context branch July 31, 2017 02:39
@anntzer anntzer mentioned this pull request Oct 22, 2017
1 task
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.

3 participants