[issue13824] argparse.FileType opens a file and never closes it

Mitar report at bugs.python.org
Mon May 6 22:51:00 EDT 2019


Mitar <mmitar at gmail.com> added the comment:

Why not make FileType instance also a context manager, so you could do something like:

with arguments.input as f:
   assert arguments.input is f

For backwards compatibility, FileType would open eagerly as now, but it would be closed at exit from context manager.

We should just make sure we do not close stdout/stderr.

----------
nosy: +mitar

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue13824>
_______________________________________


More information about the Python-bugs-list mailing list