[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-05 Thread Berker Peksag
Berker Peksag added the comment: Thanks for the suggestion, Eric. contextlib.closing(open(...)) looks unnecessary to me. Here is an alternative patch. -- Added file: http://bugs.python.org/file37601/issue18644.diff ___ Python tracker

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-05 Thread STINNER Victor
STINNER Victor added the comment: fl = contextlib.closing(open(sys.argv[1])) I prefer the current code with the explicit close() and is not sys.stdin, it's less magic :-) -- ___ Python tracker rep...@bugs.python.org

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-05 Thread Eric V. Smith
Eric V. Smith added the comment: Good point on contextlib.closing not being needed. I usually use this pattern on things that aren't files! On second thought, the with statement will close sys.stdin, so this isn't a valid pattern here. Sorry for the noise. --

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-05 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I prefer the current code (i.e. formatter_fix_resource_warning_v5.patch). In more complex case ExitStack can be used, but here it looks redundant. with contextlib.ExitStack() as stack: if some_test: fl = open(sys.argv[1])

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-05 Thread Eric V. Smith
Eric V. Smith added the comment: Not that I think it's worth changing for this case, but I find code like this better written as: if some_test: fl = contextlib.closing(open(sys.argv[1])) else: fl = sys.stdin with fl as fl: do_stuff(fl) This way you don't need another test, the

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-04 Thread Roundup Robot
Roundup Robot added the comment: New changeset f859a61f5853 by Berker Peksag in branch '3.4': Issue #18644: Fix a ResourceWarning in formatter.test(). https://hg.python.org/cpython/rev/f859a61f5853 New changeset f374e4e6d04b by Berker Peksag in branch 'default': Issue #18644: Fix a

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2015-01-04 Thread Berker Peksag
Berker Peksag added the comment: Thanks for the patch, Vajrasky. -- components: +Library (Lib) -Tests nosy: +berker.peksag resolution: - fixed stage: - resolved status: open - closed versions: +Python 3.5 ___ Python tracker rep...@bugs.python.org

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2014-12-31 Thread A.M. Kuchling
Changes by A.M. Kuchling a...@amk.ca: -- nosy: -akuchling ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18644 ___ ___ Python-bugs-list mailing

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2014-04-01 Thread R. David Murray
R. David Murray added the comment: There were a bunch of changes to pydoc in 3.4, so I'm not surprised that it doesn't use DumbWriter any more (possibly as part of the formatter pending deprecation). I think I was answering why it wasn't deprecated as part of the htmllib deprecation.

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2014-03-31 Thread A.M. Kuchling
A.M. Kuchling added the comment: Version 5 of the patch looks fine; Vajrasky, I think you can go ahead and commit it. (I didn't understand RDM's comment about pydoc using DumbWriter; in 3.4, it doesn't seem to me that pydoc does. What am I missing?) -- nosy: +akuchling

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-12 Thread Vajrasky Kok
Vajrasky Kok added the comment: Thanks, Benjamin, for reviewing my patch. Attached the fourth patch to wrap the business part inside the try ... finally. -- Added file: http://bugs.python.org/file31237/formatter_fix_resource_warning_v4.patch ___

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-12 Thread Benjamin Peterson
Benjamin Peterson added the comment: That will fail if fp is not assigned before an exception is raised. I mostly mean the part starting with the for loop. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18644

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-12 Thread Vajrasky Kok
Vajrasky Kok added the comment: Ah, sorry about that. Attached the fifth patch to only wrap for loop section inside the try... finally. -- Added file: http://bugs.python.org/file31238/formatter_fix_resource_warning_v5.patch ___ Python tracker

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-12 Thread Martijn Pieters
Martijn Pieters added the comment: The formatter module was deprecated? When? It wasn't, that's the point I am raising. The `formatter` module was exclusively used by the `htmllib` module, I am surprised the `formatter` module wasn't part of that deprecation. --

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-12 Thread R. David Murray
R. David Murray added the comment: Pydoc uses DumbWriter. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18644 ___ ___

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-11 Thread Benjamin Peterson
Benjamin Peterson added the comment: Please wrap the businesss part of the test function in a try... finally. Otherwise the patch looks good. -- nosy: +benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18644

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-09 Thread STINNER Victor
STINNER Victor added the comment: Why is the `formatter` module still part of Python 3? This was a dependency for the `htmllib` module in Python 2 only, and that module was deprecated and removed from Python 3. The formatter module was deprecated? When? -- nosy: +haypo

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Vajrasky Kok
New submission from Vajrasky Kok: This python is compiled with --with-pydebug option. [sky@localhost cpython]$ cat /tmp/a.txt manly man likes cute cat. [sky@localhost cpython]$ ./python Python 3.4.0a0 (default:e408e821d6c8, Jul 27 2013, 10:49:54) [GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Vajrasky Kok
Vajrasky Kok added the comment: Sorry, I forgot about stdin. Attached the patch to handle stdin gracefully. -- Added file: http://bugs.python.org/file31139/formatter_fix_resource_warning_v2.patch ___ Python tracker rep...@bugs.python.org

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Vajrasky Kok
Vajrasky Kok added the comment: I guess I should not close stdin just in case people are using test function in the script. Attached the patch to only close the open files not stdin. -- Added file: http://bugs.python.org/file31140/formatter_fix_resource_warning_v3.patch

[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Martijn Pieters
Martijn Pieters added the comment: Why is the `formatter` module still part of Python 3? This was a dependency for the `htmllib` module in Python 2 only, and that module was deprecated and removed from Python 3. -- nosy: +mjpieters ___ Python