[Cython] doctest wraps stdout so file pointers can't convert
Stefan Behnel
stefan_ml at behnel.de
Thu Oct 23 12:15:36 CEST 2008
Hi,
Jim Kleckner wrote:
> I ran across an annoyance and wondered if anyone else hit this.
>
> I have some compiled C code wrapped with Cython that writes to
> an ordinary file descriptor when the debug level is high enough.
> It directly references sys.stdout and sends output there. When
> using a doctest, however, that object is replaced with _SpoofOut
> that subclasses StringIO. Thus, when executing something like the
> following in a doctest:
>
> ...
> cdef file outFile = sys.stdout # This fails for the spoofed output
> callDebugCodeInC(PyFile_AsFile(outFile))
> ...
>
> It (understandably) fails on the assignment with a message:
> TypeError: Cannot convert instance to file
Note that PyFile_AsFile() was dropped in Py3 anyway, so your code will not
be future-proof if you use this.
Stefan
More information about the Cython-dev
mailing list