[New-bugs-announce] [issue14999] ctypes ArgumentError lists arguments from 1, not 0

Timothy Pederick report at bugs.python.org
Mon Jun 4 07:50:05 CEST 2012

New submission from Timothy Pederick <pederick at gmail.com>:

The ctypes ArgumentError exception indicates the location of the problem by argument number. It counts arguments starting from 1, not 0 as is typical in Python.

An example (anonymised) traceback:
    Traceback (most recent call last):
        foreign_function(a, b, c, d)
    ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

The error here was with the argument "b".

Standard, zero-indexed Python counting would suggest that argument 2 should mean "c", and "b" would be argument 1.

This may be as intended, but for me it violates the principle of least surprise.

I *think* this is the vicinity of the bug:

    _ctypes_extend_error(PyExc_ArgError, "argument %d: ", i+1);

If I'm right and the "i+1" (here and/or in subsequent lines) is the cause, that definitely makes it look intentional.

components: ctypes
messages: 162251
nosy: perey
priority: normal
severity: normal
status: open
title: ctypes ArgumentError lists arguments from 1, not 0
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list