Explicitly close files (original) (raw)

Originally reported by Brett Cannon (Bitbucket: brettcannon, GitHub: brettcannon)


There are three places in coverage.py where a file is simply opened and read from in a single line, e.g., open(file_path)read(). While technically valid, it does rely somewhat on CPython semantics of refcounting; other VMs might not close the open file quickly. It also triggers ResourceWarnings in Python 3.2 when run under development settings.

A patch is attached which adds try/finally blocks to explicitly close files.