diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-01-05 07:20:07 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-01-05 07:20:07 (GMT) |
commit | 81da286f3b64ed10d9146910e0162e72dd4c5a10 (patch) | |
tree | bac032fe07a478ad70a38e787cf770ac8179c089 /Lib/formatter.py | |
parent | dc5fdc5bb36f0ecd64fa8caa9edb16946c982469 (diff) | |
parent | d91082c777fb6494a41f85bcf56bbe4ae5ad9d37 (diff) | |
download | cpython-81da286f3b64ed10d9146910e0162e72dd4c5a10.zip cpython-81da286f3b64ed10d9146910e0162e72dd4c5a10.tar.gz cpython-81da286f3b64ed10d9146910e0162e72dd4c5a10.tar.bz2 |
Issue #18644: Fix a ResourceWarning in formatter.test().
Patch by Vajrasky Kok.
Diffstat (limited to 'Lib/formatter.py')
-rw-r--r-- | Lib/formatter.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/formatter.py b/Lib/formatter.py index 769bd6a..cc2f4ad 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) |