[Python-Dev] Add new PyErr_WarnEx() to 2.5?

Tim Peters tim.peters at gmail.com
Wed May 31 16:42:43 CEST 2006

[Ronald Oussoren, hijacking the "test_struct failure on 64 bit platforms"
> The really annoying part of the new struct warnings is that the
> warning line mentions a line in struct.py instead the caller of
> struct.pack. That makes it hard to find the source of the
> warning without telling the warnings module to raise an
> exception for DeprecationWarnings.

The problem seems to be that Python's C API apparently gives no simple
way to supply a value for warning.warn's optional `stacklevel`
argument.  The C-level signature is:

    int PyErr_Warn(PyObject *category, char *message);

and that's what _struct.c calls.  I think it would be good to add a new

    int PyErr_WarnEx(PyObject *category, char *message, long stacklevel);

C API function, change PyErr_Warn to call that forcing stacklevel to
1, and change _struct.c to call PyErr_WarnEx with stacklevel=2.  Then
it would point at struct.pack()'s caller.

More information about the Python-Dev mailing list