[issue1631171] implement warnings module in C

Brett Cannon report at bugs.python.org
Fri Nov 30 08:57:07 CET 2007


Brett Cannon added the comment:

I see two ways of implementing the fetching of a source code line from
__loader__.get_source().

One is to do it in Python.  We have a function provided that can
suppress the second line of output from a warning and just handle it in
Python code.  That has the requirement that Python code be available to
import, but if you are using Lib/warnings.py instead of
Python/_warnings.c that is pretty much guaranteed.

The other option is to rely on the fact that get_source() is supposed to
use universal newlines.  Then we can find the index of the x and x-1
newlines and print the substring between the two.  That can be done in C
code by checking for the loader, checking for get_source(), calling it,
getting the char buffer, and then just looping through looking for the
needed newlines to find the needed indexes.  Otherwise we can use the
Python API on strings to do what would have been done in pure Python,
but that is a lot of PyObject_Call() usage and seems overly inefficient
if one bothers with coding it in C.  =)

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1631171>
_____________________________________


More information about the Python-bugs-list mailing list