gh-137668: Document that ord() supports also bytes and bytearray#137669
gh-137668: Document that ord() supports also bytes and bytearray#137669serhiy-storchaka merged 2 commits intopython:mainfrom
Conversation
Doc/library/functions.rst
Outdated
| .. function:: ord(character, /) | ||
|
|
||
| Given a string representing one Unicode character, return an integer | ||
| The argument must be a one-character string or a :class:`bytes` or |
There was a problem hiding this comment.
These lines are now duplicated; what about:
character must be of length 1.
If it is a :class:str return …
If it is a :class:bytes or :class:bytearray object, return …
There was a problem hiding this comment.
Alternate suggestion: Give the length restriction once in the initial summary sentence. "Return an integer representing a character, a length 1 str, bytes, or bytearray. If a string, return the unicode ... inverse ... char. For bytes or bytearray, return the integer itself."
There was a problem hiding this comment.
What if remove any concrete types from the initial line, and only mentioned them in type-specific descriptions?
Doc/library/functions.rst
Outdated
| .. function:: ord(character, /) | ||
|
|
||
| Given a string representing one Unicode character, return an integer | ||
| The argument must be a one-character string or a :class:`bytes` or |
There was a problem hiding this comment.
What if remove any concrete types from the initial line, and only mentioned them in type-specific descriptions?
|
|
||
| Given a string representing one Unicode character, return an integer | ||
| representing the Unicode code point of that character. For example, | ||
| Return the ordinal value of a character. |
There was a problem hiding this comment.
"The ordinal value" is from the description of the original ord() function in Pascal. It explains the name of the function and can help to mnemonize it.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
pythonGH-137669) (cherry picked from commit 35759fe) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
GH-137703 is a backport of this pull request to the 3.14 branch. |
…ytearray (pythonGH-137669) (cherry picked from commit 35759fe) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-137704 is a backport of this pull request to the 3.13 branch. |
…ytearray (pythonGH-137669) (python#137703) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
📚 Documentation preview 📚: https://cpython-previews--137669.org.readthedocs.build/