Skip to content

Refactor a bit animation start/save interaction. #16078

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
Jan 5, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 3, 2020

PR Summary

1st commit:

This avoids an obscure pytest assertion failure

>           assert weakref_assertion_fn(f())
E           assert False
E            +  where False = <function <lambda> at 0x7f49d8bfdb80>(None)
E            +    where None = <weakref at 0x7f49d76c3360; dead>()

if refactoring animation and causing the test to fail. One now gets

            # If cache_frame_data is True, then the weakref should be alive;
            # if cache_frame_data is False, then the weakref should be dead (None).
>           assert (f() is None) != cache_frame_data
E           assert (None is None) != True
E            +  where None = <weakref at 0x7f4a3416c7c0; dead>()

2nd commit:

Animation connects to draw_event to figure out whether to start the
animation, but needs to temporarily disconnect the draw_event handler to
avoid triggering the animation start when saving the animation.

Instead one can just reuse the canvas._is_saving flag in the draw_event
handler to do that.

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

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

This avoids an obscure pytest assertion failure
```
>           assert weakref_assertion_fn(f())
E           assert False
E            +  where False = <function <lambda> at 0x7f49d8bfdb80>(None)
E            +    where None = <weakref at 0x7f49d76c3360; dead>()
```
if refactoring animation and causing the test to fail.  One now gets
```
            # If cache_frame_data is True, then the weakref should be alive;
            # if cache_frame_data is False, then the weakref should be dead (None).
>           assert (f() is None) != cache_frame_data
E           assert (None is None) != True
E            +  where None = <weakref at 0x7f4a3416c7c0; dead>()
```
Animation connects to draw_event to figure out whether to start the
animation, but needs to temporarily disconnect the draw_event handler to
avoid triggering the animation start when saving the animation.

Instead one can just reuse the canvas._is_saving flag in the draw_event
handler to do that.
assert weakref_assertion_fn(f())
# If cache_frame_data is True, then the weakref should be alive;
# if cache_frame_data is False, then the weakref should be dead (None).
assert (f() is None) != cache_frame_data
Copy link
Member

@timhoffm timhoffm Jan 5, 2020

Choose a reason for hiding this comment

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

Woulndn't it be more clear to add a message to the assert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the comments above are good enough, and adding code to generate the correct message would actually obfuscate the issue at hand.

@timhoffm timhoffm added this to the v3.3.0 milestone Jan 5, 2020
@timhoffm timhoffm merged commit eb18cb2 into matplotlib:master Jan 5, 2020
@anntzer anntzer deleted the animstart branch January 5, 2020 11:22
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