Skip to content
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

gh-101100: Clean up Doc/c-api/exceptions.rst and Doc/c-api/sys.rst #114825

Merged
merged 11 commits into from
Feb 11, 2024

Conversation

smontanaro
Copy link
Contributor

@smontanaro smontanaro commented Jan 31, 2024

This PR cleans up several bits in Doc/c-api/exceptions.rst:

  • suppress link to warnings.WarningMessage. It's not actually documented and isn't exposed by warnings.__all__. It's just a basic exception carrying around a message.
  • suppress link for __module__ attribute. The good stuff is in the containing paragraph.
  • suppress link for USE_STACKCHECK. The good stuff is in the documentation of PyOS_CheckStack, which is linked from the containing paragraph.
  • suppress links for three aliases for PyExc_OSError.

Since I was hunting down USE_STACKCHECK, I went ahead and suppressed the reference in Doc/c-api/sys.rst, in the documentation for PyOS_CheckStack.

I updated Doc/tools/.nitignore to remove Doc/c-api/exceptions.rst, but left an entry for Doc/c-api/sys.rst, as I didn't make an attempt to address any other problems it might have.


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

Doc/c-api/sys.rst Show resolved Hide resolved
Doc/c-api/exceptions.rst Outdated Show resolved Hide resolved
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.

If you want to specify their declaration, you can simply use typedef-like syntax.

I would move the Py_AuditHookFunction definition directly into PySys_AddAuditHook definition where it is only used. You need to add .. c:namespace:: NULL before it to avoid adding a prefix.

The PyOS_sighandler_t definition can be moved closer to PyOS_getsig() or PyOS_setsig() definitions. Duplicated description of PyOS_sighandler_t can be removed.

Doc/c-api/sys.rst Outdated Show resolved Hide resolved
Doc/c-api/sys.rst Outdated Show resolved Hide resolved
@smontanaro
Copy link
Contributor Author

Thanks @serhiy-storchaka, I believe I folded in your suggestions in a reasonable way.

Doc/c-api/sys.rst Outdated Show resolved Hide resolved
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.

It deviated significantly from initial "clean up Doc/c-api/exceptions.rst", isn't? 😉 Maybe split it on several PRs? The auditing part is not trivial.

LGTM after you do something with duplication for Py_AuditHookFunction. For example:

   .. c:namespace:: NULL
   .. c:type:: int (*Py_AuditHookFunction) (const char *event, PyObject
   *args, void *userData)

      The type of the hook function.
      *event* is (the event argument passed to PySys_Audit() or PySys_AuditTuple()),
      *args* is (...), *userData* is (the argument passed to PySys_AddAuditHook()).
      The hook function is always called ...

   See :pep:`578` for ...

@smontanaro
Copy link
Contributor Author

Feature creep is no problem. I'm retired, so have plenty of time to mess around. ;-)

Since it seems like I might have to write an actual sentence to flesh out this paragraph, I'm going to spend a bit of time reading PEP 578, but I'll have something later today.

.. c:type:: int (*Py_AuditHookFunction) (const char *event, PyObject *args, void *userData)

The type of the hook function.
*event* is (the event argument passed to PySys_Audit() or PySys_AuditTuple()),
Copy link
Member

Choose a reason for hiding this comment

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

Wait, I used parentheses to denote that it is a preliminary text, and that you should rewrite it in good English. Perhaps it is even better to describe parameters not in terms of PySys_Audit() or PySys_AuditTuple(), but in more general terms. Look at sys.audit(). Perhaps "event is a C string identifying the event" is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I recognized "(...)" as a placeholder, not the more elaborate parenthesized phrasing. Will get back to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps "event is a C string identifying the event" is enough.

I thought about that, but am not familiar enough with the C API documentation to know that descriptions of function prototypes don't simply rely on the actual prototype.

Doc/c-api/sys.rst Outdated Show resolved Hide resolved
Comment on lines 367 to 368
.. c:namespace:: NULL
.. c:type:: int (*Py_AuditHookFunction) (const char *event, PyObject *args, void *userData)
Copy link
Member

Choose a reason for hiding this comment

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

If it is not nested, c:namespace is not needed. I would prefer to make it nested, but it is only my personal preference.

Comment on lines 359 to 363
If the interpreter is initialized, this function raises an auditing event
``sys.addaudithook`` with no arguments. If any existing hooks raise an
exception derived from :class:`Exception`, the new hook will not be
added and the exception is cleared. As a result, callers cannot assume
that their hook has been added unless they control all existing hooks.
Copy link
Member

Choose a reason for hiding this comment

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

Why is it dedented? It belongs to the audit-event directive.

Doc/c-api/sys.rst Outdated Show resolved Hide resolved
Doc/c-api/sys.rst Outdated Show resolved Hide resolved
Doc/c-api/sys.rst Outdated Show resolved Hide resolved
@smontanaro
Copy link
Contributor Author

Sorry, I clearly don't understand the functional implications of the indentation. See if this latest version is more correct.

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.

LGTM.

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) February 11, 2024 18:45
@serhiy-storchaka serhiy-storchaka added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Feb 11, 2024
@serhiy-storchaka serhiy-storchaka changed the title gh-101100: clean up Doc/c-api/exceptions.rst gh-101100: Clean up Doc/c-api/exceptions.rst and Doc/c-api/sys.rst Feb 11, 2024
@serhiy-storchaka serhiy-storchaka merged commit e1552fd into python:main Feb 11, 2024
25 checks passed
@miss-islington-app
Copy link

Thanks @smontanaro for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 11, 2024
…rst (pythonGH-114825)

(cherry picked from commit e1552fd)

Co-authored-by: Skip Montanaro <skip.montanaro@gmail.com>
@miss-islington-app
Copy link

Sorry, @smontanaro and @serhiy-storchaka, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e1552fd19de17e7a6daa3c2a6d1ca207bb8eaf8e 3.11

@bedevere-app
Copy link

bedevere-app bot commented Feb 11, 2024

GH-115308 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Feb 11, 2024
@smontanaro smontanaro deleted the doc-capi branch February 11, 2024 18:57
serhiy-storchaka pushed a commit that referenced this pull request Feb 11, 2024
….rst (GH-114825) (GH-115308)

(cherry picked from commit e1552fd)

Co-authored-by: Skip Montanaro <skip.montanaro@gmail.com>
@smontanaro
Copy link
Contributor Author

@serhiy-storchaka I'll take care of the 3.11 conflict (I need the practice).

@bedevere-app
Copy link

bedevere-app bot commented Feb 11, 2024

GH-115311 is a backport of this pull request to the 3.11 branch.

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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants