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: Can't mark match, case, _ as keywords in docs
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, dom1310df, taleinat
Priority: normal Keywords:

Created on 2021-05-09 06:49 by taleinat, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg393301 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2021-05-09 06:49
Beginning in Python 3.10, `match`, `case` and `_` are "soft keywords", i.e. they are considered keywords only in specific parts of the syntax.

However, they cannot be tagged with a :keyword:`...` role in our docs.

This appears to be due to not appearing in the list of keywords in the Python lexer in Pygments, which is used by Sphinx.

I've opened an issue on the Pygments repo about this:
https://github.com/pygments/pygments/issues/1797
msg393330 - (view) Author: Dominic Davis-Foster (dom1310df) Date: 2021-05-09 18:05
I'm not sure this is a Pygments or Sphinx bug. The documentation for the :keyword: role[1] says:

   This creates a link to a reference label with that name, if it exists.


Looking at the documentation source for "Compound statements"[2] each section for a particular keyword is preceded by a reference label for the relevant keyword(s).

So for "match" and "case" all that's needed is to put the label before the section of the docs talking about them.
In fact, it seems that "match" does have a label[3], and I can link to it successfully; it's just "case" and "_" that don't work

"_" is more tricky, as you can't have a reference label called that. However, if you pick another name for the label (say, "underscore") you can use that as the target name and still have "_" as the text like so:

    :keyword:`_ <underscore>`


[1] https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-keyword
[2] https://raw.githubusercontent.com/python/cpython/main/Doc/reference/compound_stmts.rst
[3] https://github.com/python/cpython/blame/main/Doc/reference/compound_stmts.rst#L514
msg393332 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2021-05-09 18:45
Thanks Dominic, it seems that you're absolutely right!
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88250
2021-05-09 19:06:27taleinatsetstatus: open -> closed
resolution: not a bug
stage: resolved
2021-05-09 18:45:29taleinatsetmessages: + msg393332
2021-05-09 18:05:19dom1310dfsetnosy: + dom1310df
messages: + msg393330
2021-05-09 06:49:40taleinatcreate