-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
gh-136897: Update docstring of str.translate
#136954
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13477,20 +13477,21 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z) | |
str.translate as unicode_translate | ||
|
||
table: object | ||
Translation table, which must be a mapping of Unicode ordinals to | ||
Unicode ordinals, strings, or None. | ||
Translation table, which must be an object that implements indexing via __getitem__(), | ||
typically a mapping or sequence. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, explain "a mapping or sequence" of "what" :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is like this in the docs, do we want to update it too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can update both online docs(original one) and that docstring I've changed, shall we proceed with that ? |
||
/ | ||
|
||
Replace each character in the string using the given translation table. | ||
|
||
The table must implement lookup/indexing via __getitem__, for instance a | ||
dictionary or list. If this operation raises LookupError, the character is | ||
left untouched. Characters mapped to None are deleted. | ||
dictionary or list. When indexed by a Unicode ordinal, it may return another | ||
Unicode ordinal or a string to replace the character, return None to delete | ||
it, or raise LookupError to leave it unchanged. | ||
[clinic start generated code]*/ | ||
|
||
static PyObject * | ||
unicode_translate(PyObject *self, PyObject *table) | ||
/*[clinic end generated code: output=3cb448ff2fd96bf3 input=6d38343db63d8eb0]*/ | ||
/*[clinic end generated code: output=3cb448ff2fd96bf3 input=6bb9205d97271b8b]*/ | ||
{ | ||
return _PyUnicode_TranslateCharmap(self, table, "ignore"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This original wording is clearer, it describes what the object is semantically, not just the type and protocol. "a mapping of ordinals to ..." is not necessarily the same as an object conforming to the
Mapping
protocol.