Skip to content

PEP 635: fix duplicate labels - #2742

Merged
hugovk merged 2 commits into
python:mainfrom
hugovk:pep635-fix-duplicate-labels
Jul 28, 2022
Merged

hugovk merged 2 commits into
python:mainfrom
hugovk:pep635-fix-duplicate-labels

Conversation

@hugovk

@hugovk hugovk commented Jul 28, 2022 •

Copy link
Copy Markdown
Member

Fix these warnings:

pep-0635.rst:403: WARNING: duplicate label patterns, other instance in pep-0634.rst
pep-0635.rst:592: WARNING: duplicate label literal_pattern, other instance in pep-0634.rst
pep-0635.rst:681: WARNING: duplicate label capture_pattern, other instance in pep-0634.rst
pep-0635.rst:740: WARNING: duplicate label wildcard_pattern, other instance in pep-0634.rst
pep-0635.rst:907: WARNING: duplicate label sequence_pattern, other instance in pep-0634.rst
pep-0635.rst:967: WARNING: duplicate label mapping_pattern, other instance in pep-0634.rst
pep-0635.rst:1014: WARNING: duplicate label class_pattern, other instance in pep-0634.rst

Like #2735, we still get the same anchors in both:

Also remove redundant emacs metadata.

Preview

https://pep-previews--2742.org.readthedocs.build/pep-0635/

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LG (although I think it's a silly requirement that labels must be unique across all PEPs -- it doesn't scale).

@hugovk
hugovk merged commit 3d63099 into python:main Jul 28, 2022
@hugovk
hugovk deleted the pep635-fix-duplicate-labels branch July 28, 2022 19:10
@CAM-Gerlach

CAM-Gerlach commented Jul 29, 2022 •

Copy link
Copy Markdown
Member

It is a little tedious, but the whole point of Sphinx cross-references is to be able to cross reference objects across documents, even if things get moved around—the solution here is namespacing the target names by the PEP number, which still preserves the generated in-page fragments without the number. That's what the Python docs do as well, though its not as clean as here (since they have to rely on full page titles, and which don't get auto-elided).

@gvanrossum

Copy link
Copy Markdown
Member

A PEP shouldn’t have to repeat its own local namespace though IMO. (But I don’t know what Sphinx is capable of.)

@CAM-Gerlach

Copy link
Copy Markdown
Member

This works for references to, e.g., classes, functions and methods, since they are globally unique when fully qualified and don't depend on the file structure, but not so generic ref targets.

Here "namespaces" are only a convention, which can be flexible applied on a per-project (or even per-reference) basis—there is no formalized mechanism for automatic per-document namespacing. Outside of special cases like ours, it wouldn't really work well as it would defeat much of the portability and robustness of ref targets over implicit internal links, as if the document/content was ever moved, renamed, etc. it would break—and even there, it wouldn't work for things like PEP 639 (which makes extensive use of refs to avoid things breaking when I move ancillary sections out to separate files).

We could possibly implement bespoke hacks in a custom ref role and the PEP transforms to do something like this, but this might just be more trouble for authors than its worth since they might expect the standard behavior, like in the Python docs, and would have to implicitly know and remember to prepend the PEP number to references in other PEPs or the refs will not work at all.

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