Skip to content

make sure we only perform absolute imports on loading a backend #2335

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
Sep 3, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def pylab_setup():
backend_name = 'backend_'+backend
backend_name = backend_name.lower() # until we banish mixed case
backend_name = 'matplotlib.backends.%s'%backend_name.lower()

# the last argument is specifies whether to use absolute or relative
# imports. 0 means only perform absolute imports.
backend_mod = __import__(backend_name,
globals(),locals(),[backend_name])
globals(),locals(),[backend_name],0)
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment explaining the reason for explicitly setting the import to be absolute. Also, I want to make sure that ipython and spyder does not break with this. Then, I want to get this patch merged asap to let it bake and hopefully we can catch anybody else that was depending on relative imports (can't imagine how, but just to be safe).

Copy link
Author

Choose a reason for hiding this comment

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

well, from line 23 it's clear that backend_name is an absolute module name. the difference relies on how user provided strings are understood. I'll see if I can add a note where this is documented.


# Things we pull in from all backends
new_figure_manager = backend_mod.new_figure_manager
Expand Down