storborg/python-packaging — pull request #1 by dahlia (2012-11-19 01:02:17+00:00)
Title: Make readme file to be opened using with context

The previous example doesn’t explicitly close the opened `file` object. Although it's almost fine if the interpreter is CPython, but it could be broken if PyPy.

CPython does reference counting instead of garbage collections, and `file.__del__()` closes the file itself, so files are automatically closed when local scope ends unless these are *leaked* out of local scope, in CPython.

PyPy does garbage collection so invocation time of `__del__()` methods cannot be determined. It means files can be unclosed even if local scope ends and these are never leaked out.

If the `funniest` package in the example are being installed as a dependency of another package by `easy_install` using PyPy, it may cause “too many open files” error.

How to prevent this problem is to explicitly `close()` files or to `open` files using `with` context (if Python 2.5+).

Many python packages in PyPI read their readme file to fill `long_description` in `setup.py`, but this pattern without explicit closing of file should be discouraged.