Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

setattr context manager.#10314

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 1 commit intomatplotlib:masterfromanntzer:setattr-cm
Mar 26, 2018
Merged

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedJan 24, 2018
edited
Loading

PR Summary

The setattr-contextmanager that was proposed in#10292 (comment). Just quickly grepped for all the finallys in the codebase.

I also thought about doing something similar for set_prop() / get_prop() but that only appears twice throughout the codebase afaict so it's not really worth it.

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

@QuLogic
Copy link
Member

Could this be done withunittest.mock.patch or something similar?

@anntzer
Copy link
ContributorAuthor

Indeed, once we switch to Py3-only (or if we decide to add mock as a dependency) it'll be as simple as replacing cbook._setattr_cm by unittest.mock.patch.multiple...
So perhaps we may as well just wait for mpl3.

@dopplershift
Copy link
Contributor

I'd still be 👍 to merge this. It improves things, reduces the lines of code. I'm hesitant to wait for releases that are 6 months out.

timhoffm reacted with thumbs up emoji

with open(fpath, 'rb') as fh:
try:
font = afm.AFM(fh)
except RuntimeError:
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you simplify this by leaving out the inner try and catching RuntimeError in the outer try?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I guess open() cannot raise RuntimeError, so yes...

@@ -146,11 +146,6 @@ def context(style, after_reset=False):
mpl.rcdefaults()
try:
use(style)
except:
# Restore original settings before raising errors during the update.
mpl.rcParams.update(initial_settings)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this removed?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

because it's already restored in the finally: just below...

Copy link
Member

Choose a reason for hiding this comment

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

Ok, learned something new today: The finally is executed before the raise. Then, it‘s ok.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

even

try: return 1finally: return 2

will return 2...
https://docs.python.org/3/reference/compound_stmts.html#the-try-statement

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, thefinally is executed no matter what else happens.

@anntzeranntzerforce-pushed thesetattr-cm branch 4 times, most recently fromdbd5db6 to34c7ce4CompareJanuary 27, 2018 07:32
@anntzeranntzerforce-pushed thesetattr-cm branch 3 times, most recently from619460d to3fa657aCompareFebruary 15, 2018 22:33
@jklymak
Copy link
Member

Looks like this will be in MPL3.0 Did you want to make the change suggested above?

@jklymakjklymak added this to thev3.0 milestoneMar 6, 2018
@anntzer
Copy link
ContributorAuthor

Actually unittest.mock.patch.multiple does not work for previously non-existing attributes (where a delattr has to be done at the end), which we use for mpl_image_comparison_parameters. It is also nearly twice slower.
So I'm happy with keeping this implementation.

@jklymakjklymak merged commit1c5eaf6 intomatplotlib:masterMar 26, 2018
@anntzeranntzer deleted the setattr-cm branchMarch 26, 2018 21:40
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull requestAug 5, 2018
This context manager was added to master in690b213 viamatplotlib#10314.  We do not wantto backport that entire commit, however the backport ofmatplotlib#11407requires this context manger.It is private and self contained to low-risk to backport
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dopplershiftdopplershiftdopplershift left review comments

@jklymakjklymakjklymak approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.0.0
Development

Successfully merging this pull request may close these issues.

5 participants
@anntzer@QuLogic@dopplershift@jklymak@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp