Skip to content

Docs: use a Sphinx extension to eliminate excessive links#145130

Open
nedbat wants to merge 4 commits intopython:mainfrom
nedbat:nedbat/no-duplicate-links
Open

Docs: use a Sphinx extension to eliminate excessive links#145130
nedbat wants to merge 4 commits intopython:mainfrom
nedbat:nedbat/no-duplicate-links

Conversation

@nedbat
Copy link
Member

@nedbat nedbat commented Feb 22, 2026

@nedbat
Copy link
Member Author

nedbat commented Feb 22, 2026

I had a good idea: instead of writing a linter to change .rst files (pinging everyone, expecting reviews, hardcoding what's excessive, etc), now we have a Sphinx extension that does it all on the fly during the build.

@nedbat
Copy link
Member Author

nedbat commented Feb 22, 2026

Of course: if we like this, I'll publish linklint for real.

@nedbat
Copy link
Member Author

nedbat commented Feb 23, 2026

Some methods aren't unlinking properly, like ZipFile.close, but I think that's because the .rst is wrong: the methods aren't indented under the class. Is that a mistake in the .rst? Sphinx understands that "close" is "ZipFile.close", or is that because the .rst has .. method: ZipFile.close() ?

@nedbat
Copy link
Member Author

nedbat commented Feb 23, 2026

I see many classes document their methods that way, so there's more work to do.

@hugovk
Copy link
Member

hugovk commented Feb 23, 2026

In general I think this is a good idea, no big source change+pings+reviews.

We have been careful not to use third-party extensions that downstream redistributors might not have installed, and this extension would be fine: we can list it in _OPTIONAL_EXTENSIONS instead of extensions and they'll just end up with more links.


Comparing some pages that were mentioned during the discussion:

We could possibly omit links for the repeated default_factory in other paragraphs. But I understand if it's a bit risky to automate this for all paragraphs (and some are long) and anyway, it's fine to start with less unlinking and increase later.


Unlinks the second pair of str and bytes 👍


Unlinks repeats 👍

@nedbat nedbat force-pushed the nedbat/no-duplicate-links branch from 0e075de to d6100ca Compare February 28, 2026 22:48
@nedbat
Copy link
Member Author

nedbat commented Feb 28, 2026

I've updated the extension to recognize methods in different class contexts as well. It also prints a message at the end of the build. It now reports:

Linklint unlinked 3612 references.

@nedbat
Copy link
Member Author

nedbat commented Feb 28, 2026

Some methods aren't unlinking properly, like ZipFile.close, but I think that's because the .rst is wrong: the methods aren't indented under the class. Is that a mistake in the .rst? Sphinx understands that "close" is "ZipFile.close", or is that because the .rst has .. method: ZipFile.close() ?

ZipFile.close() is now unlinked in its own description.

@nedbat
Copy link
Member Author

nedbat commented Mar 1, 2026

Other interesting effects: if a type is mentioned twice in a signature, only the first instance is linked (in this case, BaseException on the logging page):
image

BTW, it seems silly to link every instance of str, int, tuple, etc in these signatures.

@nedbat nedbat changed the title WIP: Docs: use a Sphinx extension to eliminate excessive links Docs: use a Sphinx extension to eliminate excessive links Mar 1, 2026
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.

2 participants