-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-114115: Update documentation of array.array #114117
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
Conversation
from the optional *initializer* value, which must be a :class:`bytes` | ||
or :class:`bytearray` object, a unicode string, or iterable over elements | ||
of the appropriate type. |
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.
Only bytes and bytearray are special, bytes-like objects in general are not supported. List is a particular type of iterable.
If given a :class:`bytes` or :class:`bytearray` object, the initializer | ||
is passed to the new array's :meth:`frombytes` method; | ||
if given a unicode string, the initializer is passed to the | ||
:meth:`fromunicode` method; | ||
otherwise, the initializer's iterator is passed to the :meth:`extend` method | ||
to add initial items to the array. |
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.
Only bytes, bytearray and str are special, other types are just iterables, although the constructor has some more special cases for optimization.
There is a trick: extend()
rejects array
object with different typecode, but if we take iter()
, it accepts.
Actually, the constructor does not call these methods, it only executes an equivalent code, so you cannot change the behavior in subclasses by overriding them. But it is too low level implementation detail.
Doc/library/array.rst
Outdated
|
||
|
||
When an array object is printed or converted to a string, it is represented as | ||
When an array object is converted to a string, it is represented as |
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.
In very old Python printing was a separate operation from converting to string.
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@hugovk, I made yet one change after your approving, could you please look at it again? The text was not clean, |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Thank you for your help @hugovk. It is priceless to me, with my level of English. |
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
GH-114417 is a backport of this pull request to the 3.12 branch. |
GH-114418 is a backport of this pull request to the 3.11 branch. |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
📚 Documentation preview 📚: https://cpython-previews--114117.org.readthedocs.build/