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

Merged
merged 11 commits into from
Jul 10, 2025

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)

@encukou encukou merged commit 85bc89f into python:main Jul 10, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Jul 10, 2025
@encukou encukou deleted the doc-c-exceptions branch July 10, 2025 11:08
@encukou encukou added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 10, 2025
@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 10, 2025
…ythonGH-136210)

(cherry picked from commit 85bc89f)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jul 10, 2025

GH-136503 is a backport of this pull request to the 3.13 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 10, 2025
…ythonGH-136210)

(cherry picked from commit 85bc89f)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jul 10, 2025
@bedevere-app
Copy link

bedevere-app bot commented Jul 10, 2025

GH-136504 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jul 10, 2025
encukou added a commit that referenced this pull request Jul 10, 2025
…H-136210) (GH-136504)

(cherry picked from commit 85bc89f)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
encukou added a commit that referenced this pull request Jul 10, 2025
…H-136210) (GH-136503)

(cherry picked from commit 85bc89f)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy