[issue8401] Strange behavior of bytearray slice assignment

2012-11-03 Thread Ezio Melotti
Changes by Ezio Melotti : -- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed ___ Python tracker ___

[issue8401] Strange behavior of bytearray slice assignment

2012-11-03 Thread Roundup Robot
Roundup Robot added the comment: New changeset a7ebc0db5c18 by Ezio Melotti in branch 'default': Merge typo fixes (and the fix for #8401 that I wrongly merged) with 3.3. http://hg.python.org/cpython/rev/a7ebc0db5c18 -- ___ Python tracker

[issue8401] Strange behavior of bytearray slice assignment

2012-11-03 Thread Roundup Robot
Roundup Robot added the comment: New changeset 1bd2b272c568 by Ezio Melotti in branch '2.7': #8401: assigning an int to a bytearray slice (e.g. b[3:4] = 5) now raises an error. http://hg.python.org/cpython/rev/1bd2b272c568 New changeset 8f00af8abaf9 by Ezio Melotti in branch '3.2': #8401: assig

[issue8401] Strange behavior of bytearray slice assignment

2012-11-03 Thread Mark Dickinson
Mark Dickinson added the comment: The patch looks fine to me. -- nosy: +mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mail

[issue8401] Strange behavior of bytearray slice assignment

2012-10-29 Thread Ezio Melotti
Ezio Melotti added the comment: The new patch further improve tests and error message, checking for both numbers and strings: >>> b = bytearray(b'fooo') >>> b[3:4] = 'foo' TypeError: can assign only bytes, buffers, or iterables of ints in range(0, 256) >>> b[3:4] = 5 TypeError: can assign o

[issue8401] Strange behavior of bytearray slice assignment

2012-10-29 Thread Ezio Melotti
Changes by Ezio Melotti : Added file: http://bugs.python.org/file2/issue8401-2.diff ___ Python tracker ___ ___ Python-bugs-list mailing lis

[issue8401] Strange behavior of bytearray slice assignment

2012-10-27 Thread Ezio Melotti
Ezio Melotti added the comment: Updated patch against default. -- keywords: +needs review Added file: http://bugs.python.org/file27753/issue8401.diff ___ Python tracker ___ __

[issue8401] Strange behavior of bytearray slice assignment

2012-10-27 Thread Ezio Melotti
Changes by Ezio Melotti : Removed file: http://bugs.python.org/file16945/issue8401.diff ___ Python tracker ___ ___ Python-bugs-list mailing lis

[issue8401] Strange behavior of bytearray slice assignment

2012-10-06 Thread Georg Brandl
Changes by Georg Brandl : -- assignee: georg.brandl -> ezio.melotti ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscrib

[issue8401] Strange behavior of bytearray slice assignment

2012-09-26 Thread Ezio Melotti
Ezio Melotti added the comment: > >>> a[:] = -10 # This should raise ValueError, not > >>> TypeError. > >>> a[:] = 10 # This should raise OverflowError, not > >>> TypeError. FTR, these two now raise OverflowError. -- versions: +Python 3.3, Pytho

[issue8401] Strange behavior of bytearray slice assignment

2010-09-04 Thread Georg Brandl
Changes by Georg Brandl : -- assignee: -> georg.brandl ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://m

[issue8401] Strange behavior of bytearray slice assignment

2010-09-03 Thread Antoine Pitrou
Changes by Antoine Pitrou : -- stage: unit test needed -> patch review versions: -Python 2.6 ___ Python tracker ___ ___ Python-bugs-li

[issue8401] Strange behavior of bytearray slice assignment

2010-04-18 Thread Georg Brandl
Georg Brandl added the comment: Python is not (e.g.) Haskell; Python strings are not lists whose contents happen to be characters. Allowing an empty string here is a step backwards in the direction of "why not allow any string whose contents have an unambiguous meaning as bytes", i.e. the de

[issue8401] Strange behavior of bytearray slice assignment

2010-04-17 Thread Eugene Kapun
Eugene Kapun added the comment: -1 on special-casing string without an encoding. Current code does (almost) this: ... if argument_is_a_string: if not encoding_is_given: # Special case raise TypeError("string argument without an encoding") encode_argument()

[issue8401] Strange behavior of bytearray slice assignment

2010-04-16 Thread Martin v . Löwis
Martin v. Löwis added the comment: -1 on assigning strings to slices of bytearrays. As Ezio mentions, this operation conceptually requires an encoding, and no encoding is readily available in the slice assignment. -1 on special-casing empty strings. -- __

[issue8401] Strange behavior of bytearray slice assignment

2010-04-16 Thread Eugene Kapun
Eugene Kapun added the comment: __doc__ of bytearray says: > bytearray(iterable_of_ints) -> bytearray > bytearray(string, encoding[, errors]) -> bytearray > bytearray(bytes_or_bytearray) -> mutable copy of bytes_or_bytearray > bytearray(memory_view) -> bytearray So, unless an encoding is given,

[issue8401] Strange behavior of bytearray slice assignment

2010-04-16 Thread Eugene Kapun
Eugene Kapun added the comment: > Not really, chars are not ints Yes, however, empty string contains exactly zero chars. > and anyway the empty string fall in the first case. Strings aren't mentioned in documentation of bytearray slice assignment. However, I think that bytearray constructor sho

[issue8401] Strange behavior of bytearray slice assignment

2010-04-16 Thread Ezio Melotti
Ezio Melotti added the comment: Not really, chars are not ints and anyway the empty string fall in the first case. -- ___ Python tracker ___

[issue8401] Strange behavior of bytearray slice assignment

2010-04-16 Thread Eugene Kapun
Eugene Kapun added the comment: Empty string is an iterable of integers in the range 0 <= x < 256, so it should be allowed. >>> all(isinstance(x, int) and 0 <= x < 256 for x in "") True >>> bytearray()[:] = "" Traceback (most recent call last): File "", line 1, in TypeError: string argument

[issue8401] Strange behavior of bytearray slice assignment

2010-04-15 Thread Ezio Melotti
Ezio Melotti added the comment: Here is a proof of concept that fixes the problem. The doc of bytearray() says about its first arg: * If it is a string, you must also give the encoding [...]. * If it is an integer, the array will have that size and will be initialized with null bytes. * If

[issue8401] Strange behavior of bytearray slice assignment

2010-04-15 Thread Ezio Melotti
Ezio Melotti added the comment: This happens because bytearray_ass_subscript() (Objects/bytearrayobject.c:588) calls PyByteArray_FromObject() (:641) that in turn calls bytearray_init() (:746), so the results are similar to the ones returned by calling bytearray(...) directly. -- nosy

[issue8401] Strange behavior of bytearray slice assignment

2010-04-14 Thread Martin v . Löwis
Martin v. Löwis added the comment: pitrou: I agree, it should be a TypeError. -- nosy: +loewis ___ Python tracker ___ ___ Python-bugs-

[issue8401] Strange behavior of bytearray slice assignment

2010-04-14 Thread Antoine Pitrou
Antoine Pitrou added the comment: It looks rather like a bug to me, and should be forbidden. -- nosy: +pitrou priority: -> normal stage: -> needs patch versions: +Python 2.6, Python 2.7, Python 3.2 ___ Python tracker

[issue8401] Strange behavior of bytearray slice assignment

2010-04-14 Thread Eugene Kapun
New submission from Eugene Kapun : >>> a = bytearray() >>> a[:] = 0 # Is it a feature? >>> a bytearray(b'') >>> a[:] = 10 # If so, why not document it? >>> a bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') >>> a[:] = -1 Traceback (most recent call last): File "", line 1, in ValueError: