classification
Title: Obscure array.array error message
Type: behavior Stage: needs patch
Components: Extension Modules Versions: Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, alexandre.vassalotti, ezio.melotti, georg.brandl, terry.reedy
Priority: normal Keywords:

Created on 2008-08-27 01:51 by terry.reedy, last changed 2011-11-16 11:30 by ezio.melotti.

Messages (2)
msg72004 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-08-27 01:51
In 2.5
>>> import array
>>> a = array.array('b', 'fox')
>>>

In 3.0
>>> import array
>>> a = array.array('b', 'fox')
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    a = array.array('b', 'fox')
TypeError: an integer is required

This puzzled me because an integer argument most certainly is not
allowed (one would raise other exceptions.)  Then I realized that 'an
integer' here actually means 'an iterator producing integers' or more
exactly, 'an iterable whose iterator yields integers in the range
implied by the type code'.  What I would like to see is something like

TypeError: for typecode 'b', the optional initializer must be an
iterable of 1 byte integers (such as bytes).

I would also like to see a minor change in the array and array.array
docstrings.  Array.__doc__ lists the typecodes, array.array.__doc__
lists all the other info needed, so that help(array) gives everything
while help(array.array) omits the needed typecode info.  So I would like
to see the typecode info moved to the class docstring with everything
else (and replaced by 'Defines one class: array') so help(array) and
help(array.array) would both give all needed info.
msg87948 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-05-17 02:42
FWIW, in trunk the message for unicode strings is the same:
>>> array.array('b', u'fox')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required
History
Date User Action Args
2011-11-16 11:30:49ezio.melottisetnosy: + ezio.melotti

versions: + Python 3.3, - Python 3.1
2011-01-11 23:53:28eric.araujosetnosy: + alexandre.vassalotti, georg.brandl
stage: test needed -> needs patch

components: + Extension Modules, - Library (Lib)
versions: + Python 2.7, Python 3.2
2009-05-17 02:42:05ajaksu2set
nosy: + ajaksu2
versions: + Python 3.1, - Python 3.0
messages: + msg87948
priority: normal
type: behavior
stage: test needed
2008-08-27 01:51:34terry.reedycreate