This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Obscure array.array error message
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: alexandre.vassalotti Nosy List: ajaksu2, alexandre.vassalotti, ezio.melotti, georg.brandl, isoschiz, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2008-08-27 01:51 by terry.reedy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
fix_array_err_msg.patch alexandre.vassalotti, 2013-04-20 06:06 review
Messages (4)
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) * (Python triager) 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
msg187407 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-04-20 06:06
Here's a patch to fix the exception.
msg204774 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-30 04:47
New changeset 2c87d3944c7a by Alexandre Vassalotti in branch 'default':
Issue #3693: Fix array obscure error message when given a str.
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 47943
2019-05-25 23:56:23mbussonnsetpull_requests: - pull_request13484
2019-05-25 23:54:15mbussonnsetpull_requests: + pull_request13484
2013-11-30 04:48:33alexandre.vassalottisetstatus: open -> closed
assignee: alexandre.vassalotti
resolution: fixed
stage: commit review -> resolved
2013-11-30 04:47:26python-devsetnosy: + python-dev
messages: + msg204774
2013-04-21 01:55:14ezio.melottisetstage: needs patch -> commit review
versions: + Python 3.4, - Python 3.2
2013-04-20 06:06:49alexandre.vassalottisetfiles: + fix_array_err_msg.patch
keywords: + patch
messages: + msg187407
2013-04-19 00:16:54isoschizsetnosy: + isoschiz
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:05ajaksu2setpriority: normal

type: behavior
versions: + Python 3.1, - Python 3.0
nosy: + ajaksu2

messages: + msg87948
stage: test needed
2008-08-27 01:51:34terry.reedycreate