Explicitly close files · Issue #104 · nedbat/coveragepy (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@nedbat

Description

@nedbat

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.