Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid calling vars() on arbitrary third-party manager_class. #25240

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 1 commit into from
Feb 17, 2023

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 17, 2023

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

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

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.
@tacaswell tacaswell added this to the v3.7.1 milestone Feb 17, 2023
@tacaswell tacaswell merged commit 2b05ace into matplotlib:main Feb 17, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 17, 2023
@anntzer anntzer deleted the uv branch February 17, 2023 20:05
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.)
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