This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Change method of loading .py files in Python tests
> > With my debug build of Python (--with-pydebug), many tests fails because
> > of the same issue. Python scripts are loaded by the tests using this
> > pattern:
> >
> > (gdb) python exec (open ('file.py').read ())
> >
> > This causes Python to output this warning:
> >
> > __main__:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='file.py' mode='r' encoding='ANSI_X3.4-1968'>
> >
> > and the test to fail because of that extra output. Instead of using the
> > open + read + exec trick which leaks the file and causes the warning,
> > why not just source the files?
> >
> > (gdb) source file.py
>
> Maybe historical. ISTR that "source" didn't read in python
> files automatically originally. But I may easily be misremembering.
It is historical. At the beginning the idea of being able to source
a Python script using "source" generated some disagreements, and we
had to discuss a number of options before we could settle on a design
that we could agree on.
--
Joel