Avoid calling vars() on arbitrary third-party manager_class.#25240
Merged
tacaswell merged 1 commit intomatplotlib:mainfrom Feb 17, 2023
Merged
Avoid calling vars() on arbitrary third-party manager_class.#25240tacaswell merged 1 commit intomatplotlib:mainfrom
tacaswell merged 1 commit intomatplotlib:mainfrom
Conversation
vars(...) may fail if the third-party manager_class has no `__dict__`, which can happen in contrieved cases involving `__slots__` or extension modules, or more simply if the backend has no FigureCanvas attribute or if the canvas class has no manager_class attribute, in which case manager_class = None. (Note that this can only be the case if that third-party FigureCanvas doesn't inherit from FigureCanvasBase, which is probably not a great idea.) In any case, instead of vars(), inspect.getattr_static does what we want too and also handles that case. Also replace another (unrelated) use of vars() with a plain getattr.
timhoffm
approved these changes
Feb 17, 2023
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Feb 17, 2023
…-party manager_class.
rcomer
added a commit
that referenced
this pull request
Feb 18, 2023
…240-on-v3.7.x Backport PR #25240 on branch v3.7.x (Avoid calling vars() on arbitrary third-party manager_class.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
vars(...) may fail if the third-party manager_class has no
__dict__, which can happen in contrieved cases involving__slots__or extension modules, or more simply if the backend has no FigureCanvas attribute or if the canvas class has no manager_class attribute, in which case manager_class = None. (Note that this can only be the case if that third-party FigureCanvas doesn't inherit from FigureCanvasBase, which is probably not a great idea.)In any case, instead of vars(), inspect.getattr_static does what we want too and also handles that case.
Also replace another (unrelated) use of vars() with a plain getattr.
See #25227 (which is still due to pycharm being outdated, but this patch should make the error less obscure and could be relevant in other (more contrieved) cases).
PR Summary
PR Checklist
Documentation and Tests
pytestpasses)Release Notes
.. versionadded::directive in the docstring and documented indoc/users/next_whats_new/.. versionchanged::directive in the docstring and documented indoc/api/next_api_changes/next_whats_new/README.rstornext_api_changes/README.rst