This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: documentation of '%r' links to the wrong repr
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: dan.riti, docs@python, eric.araujo, ezio.melotti, georg.brandl, kyle.roberts, pitrou, python-dev, twouters
Priority: normal Keywords: easy, patch

Created on 2013-04-08 12:32 by twouters, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff_style_example.PNG kyle.roberts, 2013-04-11 03:35
diff_style_markup.PNG kyle.roberts, 2013-04-11 03:35
using-ref.patch dan.riti, 2013-04-13 16:19 Taking Kyle and Ezio comments into account.
Messages (12)
msg186292 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2013-04-08 12:32
The documentation of '%r' in http://docs.python.org/2/library/stdtypes.html#string-formatting-operations links to the wrong repr, the module (http://docs.python.org/2/library/repr.html#module-repr) instead of the builtin function (http://docs.python.org/2/library/functions.html#func-repr).
msg186379 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-09 06:12
Thanks for catching this; Sphinx’ lookup is confusing sometimes.  Using `.repr` or something similar will fix it.
msg186381 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-04-09 06:14
It just highlights the mistake we made calling a builtin module the same name as a builtin function :)
msg186475 - (view) Author: Kyle Roberts (kyle.roberts) Date: 2013-04-10 03:21
Adding a '.' to the beginning (i.e. `.repr`) creates a link to repr.html#repr.repr. This made more sense after perusing Sphinx's documentation:

"If you prefix the name with a dot, this order is reversed. For example, in the documentation of Python’s codecs module, :py:func:`open` always refers to the built-in function, while :py:func:`.open` refers to codecs.open()."

I'm not sure what other options I can try after looking at the reST documentation. It seems like our best bet would be if we could define a priority for same-name functions when two definitions are discovered. I didn't see a way to do this in Sphinx/reST so I'm not sure how to move forward with this. I'm assuming we don't want to link directly to the correct url if it can be avoided.

Also, I noticed http://docs.python.org/2/library/repr.html#module-repr links to the wrong repr() a few times where it mentions the "built-in" function.
msg186482 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-10 08:47
> It just highlights the mistake we made calling a builtin module the
> same name as a builtin function :)

But shouldn't the highlighting be handled by Pygments? 
;)
msg186508 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-04-10 15:33
You can always use a ref role instead of func.  func tries to find a module, class or function in the global Sphinx index, but ref lets you link to one specific target (see the table at the top of library/functions.rst for an example).
msg186523 - (view) Author: Kyle Roberts (kyle.roberts) Date: 2013-04-10 17:56
Ah that's the type of thing I was looking for, thanks Éric. I saw the underscored reference in functions.rst last night but figured it was just a local file link. I'll have a patch available later today. Thanks again.
msg186540 - (view) Author: Kyle Roberts (kyle.roberts) Date: 2013-04-11 03:35
So the :ref: keyword helps and creates a link, but it has the unfortunate side effect of adding different markup and style. I've attached two images to illustrate the differences. I couldn't find a way in the Sphinx or reST documentation to force it to style like a :func:, and my searches didn't come up with much either. Does anyone know of a way to style a :ref: just like a :func:?

The code I used to create the fixed link is:

:ref:`repr() <func-repr>`
msg186661 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-12 18:32
I don't think the style is so important, especially since this issue only affects 2.7.
msg186747 - (view) Author: Dan Riti (dan.riti) * Date: 2013-04-13 16:19
Reproduced the issue and generated a patch following Kyle's documented approach. 

Please note that this patch addresses the link problem, but does not address the style issue. Thanks.
msg186895 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-04-14 08:35
Fixed, thanks.
msg186896 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-14 08:35
New changeset dd5e7aef4d5b by Georg Brandl in branch '2.7':
Closes #17661: fix references to repr() going to module repr.
http://hg.python.org/cpython/rev/dd5e7aef4d5b
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61861
2013-04-14 08:35:43python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg186896

resolution: fixed
stage: needs patch -> resolved
2013-04-14 08:35:37georg.brandlsetmessages: + msg186895
2013-04-13 16:19:43dan.ritisetfiles: + using-ref.patch

nosy: + dan.riti
messages: + msg186747

keywords: + patch
2013-04-12 18:32:15ezio.melottisettype: enhancement
messages: + msg186661
stage: needs patch
2013-04-11 03:35:20kyle.robertssetfiles: + diff_style_markup.PNG
2013-04-11 03:35:07kyle.robertssetfiles: + diff_style_example.PNG

messages: + msg186540
2013-04-10 17:56:22kyle.robertssetmessages: + msg186523
2013-04-10 15:33:56eric.araujosetmessages: + msg186508
2013-04-10 08:47:45pitrousetnosy: + pitrou
messages: + msg186482
2013-04-10 03:21:34kyle.robertssetnosy: + kyle.roberts
messages: + msg186475
2013-04-09 06:14:45georg.brandlsetnosy: + georg.brandl
messages: + msg186381
2013-04-09 06:12:18eric.araujosetnosy: + ezio.melotti, eric.araujo
messages: + msg186379
2013-04-08 12:32:38twouterscreate