[3.13] gh-137668: Document that ord() supports also bytes and bytearray (GH-137669) (GH-137704)

(cherry picked from commit 35759fe2fa)
This commit is contained in:
Serhiy Storchaka 2025-08-13 12:37:15 +03:00 committed by GitHub
parent 165532ccdb
commit 3a74d52584
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 9 deletions

View file

@ -1969,15 +1969,21 @@ builtin_oct(PyObject *module, PyObject *number)
/*[clinic input]
ord as builtin_ord
c: object
character as c: object
/
Return the Unicode code point for a one-character string.
Return the ordinal value of a character.
If the argument is a one-character string, return the Unicode code
point of that character.
If the argument is a bytes or bytearray object of length 1, return its
single byte value.
[clinic start generated code]*/
static PyObject *
builtin_ord(PyObject *module, PyObject *c)
/*[clinic end generated code: output=4fa5e87a323bae71 input=3064e5d6203ad012]*/
/*[clinic end generated code: output=4fa5e87a323bae71 input=98d38480432e1177]*/
{
long ord;
Py_ssize_t size;

View file

@ -806,10 +806,16 @@ PyDoc_STRVAR(builtin_oct__doc__,
{"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__},
PyDoc_STRVAR(builtin_ord__doc__,
"ord($module, c, /)\n"
"ord($module, character, /)\n"
"--\n"
"\n"
"Return the Unicode code point for a one-character string.");
"Return the ordinal value of a character.\n"
"\n"
"If the argument is a one-character string, return the Unicode code\n"
"point of that character.\n"
"\n"
"If the argument is a bytes or bytearray object of length 1, return its\n"
"single byte value.");
#define BUILTIN_ORD_METHODDEF \
{"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__},
@ -1228,4 +1234,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
/*[clinic end generated code: output=435d3f286a863c49 input=a9049054013a1b77]*/
/*[clinic end generated code: output=f686ad843368963c input=a9049054013a1b77]*/