Skip to content

gh-90120: Specify UTF-8 encoding in PyModule_AddString{Constant,Macro} docs #131597

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 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Doc/c-api/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ state:
Add a string constant to *module* as *name*. This convenience function can be
used from the module's initialization function. The string *value* must be
``NULL``-terminated.
``NULL``-terminated and UTF-8 encoded.
Return ``-1`` with an exception set on error, ``0`` on success.
This is a convenience function that calls
Expand All @@ -651,7 +651,13 @@ state:
.. c:macro:: PyModule_AddStringMacro(module, macro)
Add a string constant to *module*.
Add a string constant to *module*. The name and the value are taken from
*macro*. For example ``PyModule_AddStrMacro(module, STRINGLIB_TYPE_NAME)``
adds the string constant *STRINGLIB_TYPE_NAME* with the value of
*STRINGLIB_TYPE_NAME* to *module*. The string *value* must be
``NULL``-terminated and UTF-8 encoded.
Comment on lines +657 to +658
Copy link
Member

Choose a reason for hiding this comment

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

value is not a variable we know about here. It makes sense for PyModule_AddStringConstant because there's a value parameter.

Instead, let's do something like this:

Suggested change
*STRINGLIB_TYPE_NAME* to *module*. The string *value* must be
``NULL``-terminated and UTF-8 encoded.
*STRINGLIB_TYPE_NAME* to *module*. The contents of the macro must be
``NULL``-terminated and UTF-8 encoded.

I think it would also make more sense to move that sentence to before "For example".

Return ``-1`` with an exception set on error, ``0`` on success.
.. c:function:: int PyModule_AddType(PyObject *module, PyTypeObject *type)
Expand Down
Loading