Skip to content

gh-137668: Document that ord() supports also bytes and bytearray #137669

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

Merged
merged 2 commits into from
Aug 13, 2025

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Aug 12, 2025


Given a string representing one Unicode character, return an integer
The argument must be a one-character string or a :class:`bytes` or
Copy link
Member

Choose a reason for hiding this comment

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

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 …

Copy link
Member

Choose a reason for hiding this comment

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

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."

Copy link
Member Author

Choose a reason for hiding this comment

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

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
The argument must be a one-character string or a :class:`bytes` or
Copy link
Member Author

Choose a reason for hiding this comment

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

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.
Copy link
Member Author

Choose a reason for hiding this comment

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

"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.

@serhiy-storchaka serhiy-storchaka merged commit 35759fe into python:main Aug 13, 2025
47 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Aug 13, 2025
@miss-islington-app
Copy link

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the docs-ord-bytes branch August 13, 2025 09:12
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 13, 2025
pythonGH-137669)

(cherry picked from commit 35759fe)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@miss-islington-app
Copy link

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

cherry_picker 35759fe2faf1443455dfcb15ef7c435e34b492c7 3.13

@bedevere-app
Copy link

bedevere-app bot commented Aug 13, 2025

GH-137703 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Aug 13, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Aug 13, 2025
…ytearray (pythonGH-137669)

(cherry picked from commit 35759fe)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Aug 13, 2025

GH-137704 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Aug 13, 2025
serhiy-storchaka added a commit that referenced this pull request Aug 13, 2025
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
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants