Revert "Convert adjust_bbox to use ExitStack." #18089
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
With the
ExitStack
and context managers, it's expected that everything is called in pairs, i.e.,adjust_bbox
followed byrestore_bbox
. When saving,BackendBases.print_figure
callsadjust_bbox
before andrestore_bbox
after the renderer-specific method. In raster renderers, that's all that happens.However, in mixed mode renderers, this is not the case. When it needs to rasterize (
MixedModeRendering.start_rasterizing
), it will change the DPI, restore the bbox, and re-adjust again. Internally, it hangs on to the newrestore_bbox
, butprint_figure
still has the original, which was cleared at the firststart_rasterizing
call, so when it callsrestore_bbox
, it does nothing because the stack is empty.So all that means that we need to revert the original change, as it needs to be possible to call
restore_bbox
more than once. This has not been a direct revert, as other cleanups happened in the meantime.Fixes #18061.
PR Checklist