Skip to content

gh-46236: PyUnicode docs improvements - #129966

Merged
encukou merged 6 commits into
python:mainfrom
encukou:pyunicode-docs
Feb 28, 2025
Merged

gh-46236: PyUnicode docs improvements#129966
encukou merged 6 commits into
python:mainfrom
encukou:pyunicode-docs

Conversation

@encukou

@encukouencukou commented Feb 10, 2025

Copy link
Copy Markdown
Member

While planning to deprecate the PyASCIIObject structs, I found some docs improvements. IMO, these should be applied (and backported) regardless of what happens to PyASCIIObject.

Move deprecated PyUnicode API docs to new section

I intend to add more here. IMO, it's good practice to separate deprecated API out like this.

  • Move Py_UNICODE here.
  • Formally soft-deprecate PyUnicode_READY, and move it here.
  • Document and soft-deprecate PyUnicode_IS_READY, and move it here.

Document PyUnicode_IS_ASCII, PyUnicode_CHECK_INTERNED

PyUnicode_New: Clarify requirements for "fresh" strings

Also, refer to PyUnicode_New wrom all the "writers" for which you need to follow the requirements

PyUnicodeWriter_DecodeUTF8Stateful: Link "error-handlers"


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

Move Py_UNICODE to a new "Deprecated API" section.
Formally soft-deprecate PyUnicode_READY, and move it
Document and soft-deprecate PyUnicode_IS_READY, and move it
@encukou

Copy link
Copy Markdown
MemberAuthor

@vstinner@serhiy-storchaka Do these changes look OK to you?

Comment threadDoc/c-api/unicode.rst

.. c:function:: unsigned int PyUnicode_IS_ASCII(PyObject *unicode)

Return true if the string only contains ASCII characters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Return true if the string only contains ASCII characters.
Return non-zero if the string only contains ASCII characters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"Return true" is common for such functions (see for example PyUnicode_Check()).

Comment threadDoc/c-api/unicode.rst Outdated

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a couple of suggestion, but in general LGTM. 👍

Comment threadDoc/c-api/unicode.rst Outdated
Comment threadDoc/c-api/unicode.rst

.. c:function:: unsigned int PyUnicode_IS_ASCII(PyObject *unicode)

Return true if the string only contains ASCII characters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"Return true" is common for such functions (see for example PyUnicode_Check()).

Comment threadDoc/c-api/unicode.rst

.. c:function:: unsigned int PyUnicode_CHECK_INTERNED(PyObject *str)

Return a non-zero value if *str* is interned, zero if not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Most documentation uses "Return true" (60 occurrences), some use "Return non-zero" (13 occurrences) and one uses "Return a non-zero".

In this case using "Return a non-zero" looks justified, as it may encode additional information.

Comment threadDoc/c-api/unicode.rst Outdated
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

@vstinnervstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@encukou

Copy link
Copy Markdown
MemberAuthor

Thank you for the reviews!

@encukou
encukou merged commit e21863c into python:mainFeb 28, 2025
@github-project-automationgithub-project-automationBot moved this from Todo to Done in Docs PRsFeb 28, 2025
@encukou
encukou deleted the pyunicode-docs branch February 28, 2025 14:11
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docsDocumentation in the Doc dirskip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

@encukou@vstinner@serhiy-storchaka