Skip to content

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jan 16, 2024

Comment on lines 82 to 84
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.
Copy link
Member Author

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.

Comment on lines 86 to 91
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.
Copy link
Member Author

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.



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

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>
@serhiy-storchaka
Copy link
Member Author

@hugovk, I made yet one change after your approving, could you please look at it again? The text was not clean, tounicode() also "converts array to string", but that paragraph was about repr().

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@serhiy-storchaka
Copy link
Member Author

Thank you for your help @hugovk. It is priceless to me, with my level of English.

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) January 22, 2024 08:38
@serhiy-storchaka serhiy-storchaka merged commit 650f9e4 into python:main Jan 22, 2024
@miss-islington-app
Copy link

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

@miss-islington-app
Copy link

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

cherry_picker 650f9e4c94711ff49ea4e13bf800945a6147b7e0 3.12

@miss-islington-app
Copy link

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

cherry_picker 650f9e4c94711ff49ea4e13bf800945a6147b7e0 3.11

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jan 22, 2024
…-114117)

(cherry picked from commit 650f9e4)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Jan 22, 2024

GH-114417 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Jan 22, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jan 22, 2024
…-114117)

(cherry picked from commit 650f9e4)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Jan 22, 2024

GH-114418 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Jan 22, 2024
serhiy-storchaka added a commit that referenced this pull request Jan 22, 2024
…-114418)

(cherry picked from commit 650f9e4)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
serhiy-storchaka added a commit that referenced this pull request Jan 22, 2024
…-114417)

(cherry picked from commit 650f9e4)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants