Skip to content

gh-136209: Add .. c:var:: declarations for C exception types #136210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

encukou
Copy link
Member

@encukou encukou commented Jul 2, 2025

  • Add .. c:var:: declarations for C exception types. (This needs the type, and adds stable ABI declarations.)
  • Convert to list-table to avoid overlong lines
  • Merge the 3 tables -- these objects aren't very distinct
  • Remove the note about what's a base class. (This wasn't kept to date, and it isn't very useful info. Exceptions can grow subclasses in future Python versions anyway.)
  • Name the notes for more clarity
  • Remove properly documented names from nitpick_ignore

📚 Documentation preview 📚: https://cpython-previews--136210.org.readthedocs.build/

@encukou encukou requested review from AA-Turner and hugovk as code owners July 2, 2025 15:40
@encukou encukou added the docs Documentation in the Doc dir label Jul 2, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Jul 2, 2025
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@serhiy-storchaka
Copy link
Member

I tried to do this before, but gave up when I saw that it was impossible to get rid of PyObject * until we can use :no-typesetting: in Sphinx 7.2. And now it generates also recurring "Part of the Stable ABI" which increases the table height.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Is it possible to add space between three tables? Each table has certain order. When they are merged, there is no order.

@hugovk
Copy link
Member

hugovk commented Jul 7, 2025

until we can use :no-typesetting: in Sphinx 7.2.

We now can! We're using Sphinx 8.2 for 3.12+ (and 7.2 for 3.11):

sphinx~=8.2.0

@encukou
Copy link
Member Author

encukou commented Jul 9, 2025

:no-typesetting: inflates the source table height.
I personally prefer the “real”-looking definitions with PyObject * and stable ABI notes. To me, these are primarily link targets that you jump to from a search. Who'll scroll up to read the introduction?

But, I'm OK with this :no-typesetting: version too.

Is it possible to add space between three tables? Each table has certain order. When they are merged, there is no order.

I think it's only possible with three separate tables, with misaligned columns.
Do you like this better?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. I like the 3 tables. It's closer to the documentation of Python exceptions: https://docs.python.org/dev/library/exceptions.html (grouped by categories, as C API exceptions now).

I have no opinion on :no-typesetting:.

:c:var:`!PyExc_WindowsError` is only defined on Windows; protect code that
uses this by testing that the preprocessor macro ``MS_WINDOWS`` is defined.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe here is a better place for .. _standardwarningcategories:, no?

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Thank you for your update.

I have no strong preference about the look of the definitions. Stable ABI notes has their value, although they are repetitive and take much space. We could add notes or a special column for the stable ABI version, but this will make the sources even larger. So I left this on you and other reviewers.

Three tables with separate subsection names look much better to me. If you want to align column widths, there is a ways to specify column widths explicitly.

@encukou
Copy link
Member Author

encukou commented Jul 10, 2025

I'll go with the “full” info for this PR, then. It can be slimmed down in the future.
An issue is that the Stable ABI notes are autogenerated (so that documentarians don't need to care about them); moving them elsewhere would mean maintaining them manually.

For future reference, I'm attaching screenshots of both variants, and a little script I used to add the :no-typesetting: everywhere, so anyone can easily experiment :)

With “real” definitions -- bigger but more complete:
image

With :no-typesetting: and :c:var: -- leaner:
image

Script to add :no-typesetting:
filename = 'Doc/c-api/exceptions.rst' DEFINITION_START = ' * * .. c:var:: PyObject *' with open(filename) as f: lines = list(f) new_lines = [] for line in lines: new_lines.append(line) if line.startswith(DEFINITION_START): name = line.removeprefix(DEFINITION_START) new_lines.append(' :no-typesetting:\n') new_lines.append('\n') new_lines.append(f' :c:var:`!{name.strip()}`\n') with open(filename, 'w') as f: f.writelines(new_lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge docs Documentation in the Doc dir skip news
4 participants