[issue18151] Idlelib: update to "with open ... except OSError" (in 2.7, leave IOError)

Terry J. Reedy report at bugs.python.org
Thu Jun 6 20:30:43 CEST 2013


Terry J. Reedy added the comment:

Here is the 'OS' version of the fix and update to grep_it. Change 'OS' to 'IO' on line 17 to apply to current 3.3, without the io2os patch.  Besides using 'with', it iterates the files directly instead of iterating blocks of readlines. The two changes make the code simpler and cleaner. The changed summary looks better to me, besides avoiding the hit/hits problem.

As can be seen in the io2os patch, there are other opens to be updated in another patch.

OutputWindow.OutputWindow._file_line_helper has this one:
                    f = open(filename, "r")
                    f.close()
which would become:
                    with open(filename, "r"): pass

This tests whether the filename extracted from a traceback or grep report is correct (can be opened). (Each of several patterns are tried until one works.) The opened file is discarded because the filename is returned to be passes to editwin's flist.open. I believe this could be replaced by an os.stat() call.

Backportint to 2.7 is the subject of #18152

----------
keywords: +needs review
Added file: http://bugs.python.org/file30486/grep_it.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18151>
_______________________________________


More information about the Python-bugs-list mailing list