[Python-3000] need help fixing broken tests in py3k-pep3137 branch

Paul Moore p.f.moore at gmail.com
Sat Nov 3 15:23:02 CET 2007


On 03/11/2007, Christian Heimes <lists at cheimes.de> wrote:
> You are partly right. The documentation needs an update. It should say
> "which mist be a list, string, byte sequence or iterable ...".

Actually, "string" is a holdover from the Python 2.x behaviour you
point out below. In 3.x, strings are not special:

>>> array.array('H',"1234")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

Also, based on Nick Coghlan's comment, this should be an object
implementing the buffer protocol rather than a byte sequence. This
isn't the case in Python 2.x, but seems to be in Python 3.0.

So, the wording should probably be: "which must be a list, object
supporting the buffer interface or iterable ...".

> In Python 2.x the array module handles strings in the same way:
>
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import array
> >>> array.array('H', "1234")
> array('H', [12849, 13363])
>
> Bytes are the successor of Python 2.x's byte strings (str). They are
> even using the same C type PyString. My patch has only restored the old
> behavior of PyString.

OK, thanks for the clarification (again!).

Paul


More information about the Python-3000 mailing list