From d91082c777fb6494a41f85bcf56bbe4ae5ad9d37 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 5 Jan 2015 09:19:40 +0200 Subject: [PATCH] Issue #18644: Fix a ResourceWarning in formatter.test(). Patch by Vajrasky Kok. --- Lib/formatter.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/formatter.py b/Lib/formatter.py index d8cca52e307..9338261be7c 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)