# Using Sphinx 3's C domain syntax

**URL:** <https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500>\
**Category:** Documentation\
**Created:** [June 13, 2022, 1:51pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500 "2022-06-13T13:51:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AA-Turner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aa-turner/32/4979_2.png) [@AA-Turner](https://discuss.python.org/u/AA-Turner)\
**Post date:** [June 13, 2022, 1:51pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/1 "2022-06-13T13:51:30Z")

</div>

Opening this discussion per @encukou from [GH-93738](https://github.com/python/cpython/issues/93738#issuecomment-1153848146).

# Synopsis

CPython recently updated all active bugfix branches to require Sphinx 3.2. This allows using the C domain syntax introduced in Sphinx 3 ([docs](https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#the-c-domain)).

I propose updating the CPython docs to use this new syntax

# Background

Sphinx would additionally like to remove support for the pre-v3 syntax, and Python is the only large project using it. (The Linux kernel has migrated to the new syntax.)

The parsing in the new C domain is a lot stricter, meaning that e.g. `:c:type:`const char*` ` is no longer valid.

I proposed this migration on [the issue tracker](https://github.com/python/cpython/issues/93738) and there seemed to be general consensus, this message is for promulgation to a wider audience.

Please let me know any thoughts or objections to the proposed change. My remaining questions are roughly:

- Is this change welcome?
- Does anybody have other concerns?

A

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [June 13, 2022, 2:30pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/2 "2022-06-13T14:30:09Z")

</div>

FWIW, the main change is that `:c:type:`, `:c:func:`, etc. need **exact** type/function names, and anything more complicated needs to be `:c:expr:`, for example:

```
:c:expr:`PyObject*`
:c:expr:`const PyBytesObject*`
:c:expr:`Py_CLEAR(obj)`

```

Spinx will parse the expression, add syntax highlighting, and – importantly – linkify names (`PyObject` and `Py_CLEAR` above).

The disadvantage is losing support for Sphinx 2. IMO, that’s reasonable at this point.

---

<div class="post-metadata">

**Author:** ![AA-Turner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aa-turner/32/4979_2.png) [@AA-Turner](https://discuss.python.org/u/AA-Turner)\
**Post date:** [June 13, 2022, 2:32pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/3 "2022-06-13T14:32:51Z")

</div>

> [@encukou](#):
>
> The disadvantage is losing support for Sphinx 2

For explicitness, we’ve already lost (declared) support for Sphinx 2 per [GH-93337](https://github.com/python/cpython/pull/93337) (I should have put a link to this PR in my original post, sorry.)

A

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [June 13, 2022, 2:35pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/4 "2022-06-13T14:35:44Z")

</div>

The proposal is to backport this to 3.11 and 3.10, right?

---

<div class="post-metadata">

**Author:** ![AA-Turner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aa-turner/32/4979_2.png) [@AA-Turner](https://discuss.python.org/u/AA-Turner)\
**Post date:** [June 13, 2022, 2:47pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/5 "2022-06-13T14:47:56Z")

</div>

> [@encukou](#):
>
> backport this to 3.11 and 3.10

Yes, to allow future backports without conflicts (Victor and Serhiy agreed).

A

---

<div class="post-metadata">

**Author:** ![ezio-melotti](https://avatars.discourse-cdn.com/v4/letter/e/f17d59/32.png) [@ezio-melotti](https://discuss.python.org/u/ezio-melotti)\
**Post date:** [June 13, 2022, 7:27pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/6 "2022-06-13T19:27:13Z")

</div>

> [@AA-Turner](#):
>
> Does anybody have other concerns?

I’m assuming Sphinx will give an error if you use `:c:type:`/`:c:func:` for expressions, right?  
I think it might take a bit for people to adjust to the change, so it’s important that the (now) wrong markup gets recognized quickly by Sphinx, possibly pointing to the correct markup (e.g. `:c:expr:`). Are you aware of any cases that fail silently and/or produce the wrong result? Should `sphinx-lint` be updated to catch any of those?

Given the scope of the change, do you think the commit(s) should be added to [`.git-blame-ignore-revs`](https://github.blog/changelog/2022-03-24-ignore-commits-in-the-blame-view-beta/)? If you do, it’s probably easier to just have a few big commits rather than many small ones (e.g. one per file). (Having few commits might be better regardless IMHO).

The [devguide](https://devguide.python.org/documenting/#information-units) will also need to be updated.

---

<div class="post-metadata">

**Author:** ![AA-Turner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aa-turner/32/4979_2.png) [@AA-Turner](https://discuss.python.org/u/AA-Turner)\
**Post date:** [June 13, 2022, 9:43pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/7 "2022-06-13T21:43:52Z")

</div>

> [@ezio-melotti](#):
>
> I’m assuming Sphinx will give an error if you use `:c:type:`/`:c:func:` for expressions, right?

It fails, yes (a warning is emitted that then fails the build as we pass `-W`).

> [@ezio-melotti](#):
>
> Are you aware of any cases that fail silently and/or produce the wrong result?

Not personally, no.

> [@ezio-melotti](#):
>
> Given the scope of the change, do you think the commit(s) should be added to [`.git-blame-ignore-revs`](https://github.blog/changelog/2022-03-24-ignore-commits-in-the-blame-view-beta/)?

From one perspective it is large but from another it isn’t – Victor linked [GH-84385](https://github.com/python/cpython/issues/84385) which contains many similar sized changes – if I break up into one PR per commit as Petr originally suggested it would be even smaller diff sizes.

A

---

<div class="post-metadata">

**Author:** ![ambv](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ambv/32/25884_2.png) [@ambv](https://discuss.python.org/u/ambv)\
**Post date:** [June 21, 2022, 3:05pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/8 "2022-06-21T15:05:25Z")

</div>

I’m +1 to going ahead with this. I can review+merge each of the PRs needed for this.

---

<div class="post-metadata">

**Author:** ![AA-Turner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aa-turner/32/4979_2.png) [@AA-Turner](https://discuss.python.org/u/AA-Turner)\
**Post date:** [October 3, 2022, 5:34pm UTC](https://discuss.python.org/t/using-sphinx-3s-c-domain-syntax/16500/9 "2022-10-03T17:34:30Z")

</div>

I’ve opened PRs to implement this (one-ish per commit in my original branch, as Petr suggested)–all are now listed in the introduction to [GH-93738](https://github.com/python/cpython/issues/93738).

A
