diff --git a/Lib/formatter.py b/Lib/formatter.py index 769bd6a90a5..cc2f4ad18b1 100644 --- a/Lib/formatter.py +++ b/Lib/formatter.py @@ -436,11 +436,15 @@ def test(file = None): fp = open(sys.argv[1]) else: fp = sys.stdin - for line in fp: - if line == '\n': - f.end_paragraph(1) - else: - f.add_flowing_data(line) + try: + for line in fp: + if line == '\n': + f.end_paragraph(1) + else: + f.add_flowing_data(line) + finally: + if fp is not sys.stdin: + fp.close() f.end_paragraph(0)