Avoid calling vars() on arbitrary third-party manager_class. #25240
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
pytest
passes)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.rst
ornext_api_changes/README.rst