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

Skip to content

Ensure shortened module path points to expected object. #273

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
Jul 31, 2017

Conversation

QuLogic
Copy link
Contributor

@QuLogic QuLogic commented Jul 29, 2017

For example, matplotlib.pyplot.figure can be shortened to matplotlib.figure, but the former is a function (that is used a lot) while the latter is a module (which is generally used much less).

@QuLogic
Copy link
Contributor Author

QuLogic commented Jul 29, 2017

This might be a bit overcautious if something like a top-level shortcut like from a import foo exists when the actual object is a.b.c.d.foo and a.b.foo exists as a different object (or similar), but it's better than pointing to the wrong object altogether.

@@ -76,12 +76,21 @@ def get_mapping(self):

def get_short_module_name(module_name, obj_name):
""" Get the shortest possible module name """
scope = {}
try:
exec('from %s import %s' % (module_name, obj_name), scope, scope)
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a comment to highlight what/why this is being called here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

For example, `matplotlib.pyplot.figure` can be shortened to
`matplotlib.figure`, but the former is a function (that is used a lot)
while the latter is a module (which is generally used much less).
@QuLogic QuLogic force-pushed the fix-module-short-name branch from 303c307 to 6025b73 Compare July 30, 2017 03:04
@Titan-C
Copy link
Member

Titan-C commented Jul 31, 2017

This works well enough for me. I'm merging this.

@Titan-C Titan-C merged commit cba4b1c into sphinx-gallery:master Jul 31, 2017
@QuLogic QuLogic deleted the fix-module-short-name branch July 31, 2017 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants