# Overlinking in dataclass() doc

**URL:** <https://discuss.python.org/t/overlinking-in-dataclass-doc/48948>\
**Category:** Documentation\
**Created:** [March 19, 2024, 1:20pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948 "2024-03-19T13:20:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [March 19, 2024, 1:20pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/1 "2024-03-19T13:20:51Z")

</div>

In the [dataclass()](https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass) docs, every instance of `dataclass()` is a link, but to the very section I’m already reading. This seems unhelpful and distracting. Do people agree?

Also, “special methods” is linked but without the trailing s: [special method](https://docs.python.org/3/glossary.html#term-special-method)s. This is because it’s to the glossary entry for “special method”. This seems overly pedantic. The link should be on the entire word, yes?

---

<div class="post-metadata">

**Author:** ![hugovk](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hugovk/32/14505_2.png) [@hugovk](https://discuss.python.org/u/hugovk)\
**Post date:** [March 19, 2024, 1:26pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/2 "2024-03-19T13:26:26Z")

</div>

Yes to both.

There’s no need to link to itself, we can disable those with the `!` prefix.

And we can use something like this to get a link like [special methods](https://docs.python.org/3/glossary.html#term-special-method):

```diff
-:term:`special method`s
+:term:`special methods <special method>

```

---

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [March 19, 2024, 1:40pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/3 "2024-03-19T13:40:52Z")

</div>

> [@hugovk](#):
>
> There’s no need to link to itself, we can disable those with the `!` prefix.

I would have simply removed the “:func:`dataclass`” markup, but I guess the `!` prefix keeps the typographic style but suppresses the link?

---

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [March 19, 2024, 1:55pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/4 "2024-03-19T13:55:06Z")

</div>

> <https://github.com/python/cpython/pull/117005>
>
> As discussed here: https://discuss.python.org/t/overlinking-in-dataclass-doc/489…48
> 
> 
> \----
> 📚 Documentation preview 📚: https://cpython-previews--117005.org.readthedocs.build/

---

<div class="post-metadata">

**Author:** ![hugovk](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hugovk/32/14505_2.png) [@hugovk](https://discuss.python.org/u/hugovk)\
**Post date:** [March 19, 2024, 1:55pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/5 "2024-03-19T13:55:29Z")

</div>

> [@nedbat](#):
>
> I would have simply removed the “:func:`dataclass`” markup, but I guess the `!` prefix keeps the typographic style but suppresses the link?

Yup:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/3/4/34f21e3bfefd05be19863b5f3a4286486892f1c7.png)

---

<div class="post-metadata">

**Author:** ![nedbat](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nedbat/32/8744_2.png) [@nedbat](https://discuss.python.org/u/nedbat)\
**Post date:** [March 19, 2024, 2:04pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/6 "2024-03-19T14:04:08Z")

</div>

Now I’m wondering if someone with Sphinx internals super-powers could write a linter of sorts to detect when a link is redundantly headed to its own section. Probably there are too many edge cases and ambiguities (what is the “same section”?)

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [March 19, 2024, 5:26pm UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/7 "2024-03-19T17:26:57Z")

</div>

> [@nedbat](#):
>
> Now I’m wondering if someone with Sphinx internals super-powers could write a linter of sorts to detect when a link is redundantly headed to its own section.

Kinda like how Wikipedia works? A link to the current page is rendered in bolt instead of as a link? That’d be useful.

> [@nedbat](#):
>
> (what is the “same section”?)

IMO whatever’s simplest, eg “the most recent heading” or “all heading levels moving up the tree”. Either of those would be fine, as would probably any other simple rule.

---

<div class="post-metadata">

**Author:** ![CAM-Gerlach](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cam-gerlach/32/3688_2.png) [@CAM-Gerlach](https://discuss.python.org/u/CAM-Gerlach)\
**Post date:** [March 20, 2024, 1:27am UTC](https://discuss.python.org/t/overlinking-in-dataclass-doc/48948/8 "2024-03-20T01:27:09Z")

</div>

As Hugo mentioned, after discussion we all agreed that it was redundant and potentially confusing to link things to themselves, and the simplest way to disable the link (and also preserve the markup) is to just add `!` in front of it.

> [@nedbat](#):
>
> Now I’m wondering if someone with Sphinx internals super-powers could write a linter of sorts to detect when a link is redundantly headed to its own section.

I’ve mucked around with this like this and it _should_ be possible to do as a doctree transform, but it would likely be kinda tricky and annoying as there are lots of different ref types (and each domain has differences in how xref resolution is implemented) and many cases to handle with many layers of nested nodes (as I see this more commonly with functions, classes, etc. vs section refs). However, if we _do_ implement it, it would be comparatively trivial to just make it automatically disable link resolution and add a special class (that could be used in CSS to style such specially, like on Wikipedia as Chris mentions), rather than just issuing a warning and making the user fix it themself.

> [@hugovk](#):
>
> ```diff
> -:term:`special method`s
> 
> ```

Just to note, this is invalid syntax; it would need to be `:term:`special method`\s`.
