Skip to content
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

Source link in doc of printoptions goes to contextlib #11639

Closed
kohr-h opened this issue Jul 30, 2018 · 6 comments
Closed

Source link in doc of printoptions goes to contextlib #11639

kohr-h opened this issue Jul 30, 2018 · 6 comments

Comments

@kohr-h
Copy link
Contributor

kohr-h commented Jul 30, 2018

The source link in the documentation of the new printoptions context manager has the wrong link target: it goes to the invalid

http://github.com/anaconda3/lib/python3.6/contextlib.py#L281-L311

Seems like an issue with the link auto-generation machinery, maybe even with other decorated functions?

@eric-wieser
Copy link
Member

eric-wieser commented Jul 30, 2018

I think this might be a sphinx bug, assuming we're using sphinx.ext.linkcode

@eric-wieser
Copy link
Member

eric-wieser commented Jul 30, 2018

Nope, this is a bug in our own code - good find!

numpy/doc/source/conf.py

Lines 303 to 348 in 83828f5

def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
"""
if domain != 'py':
return None
modname = info['module']
fullname = info['fullname']
submod = sys.modules.get(modname)
if submod is None:
return None
obj = submod
for part in fullname.split('.'):
try:
obj = getattr(obj, part)
except Exception:
return None
try:
fn = inspect.getsourcefile(obj)
except Exception:
fn = None
if not fn:
return None
try:
source, lineno = inspect.getsourcelines(obj)
except Exception:
lineno = None
if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""
fn = relpath(fn, start=dirname(numpy.__file__))
if 'dev' in numpy.__version__:
return "https://github.com/numpy/numpy/blob/master/numpy/%s%s" % (
fn, linespec)
else:
return "https://github.com/numpy/numpy/blob/v%s/numpy/%s%s" % (
numpy.__version__, fn, linespec)

In particular, inspect.getsourcefile will not behave usefully on a contextlib contextmanager. inspect.unwrap should solve that problem

@eric-wieser
Copy link
Member

This relates to https://bugs.python.org/issue1764286

@kohr-h
Copy link
Contributor Author

kohr-h commented Aug 1, 2018

Wow, that was quick! Interesting that it turned up an inconsistency in the Python standard library.

@eric-wieser
Copy link
Member

Upstream fix at python/cpython#8602

@eric-wieser
Copy link
Member

Upstream fix still waiting for review - I think a review from a non core developer would move the process forwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants