[issue13824] argparse.FileType opens a file and never closes it
paul j3
report at bugs.python.org
Tue Apr 1 09:36:51 CEST 2014
paul j3 added the comment:
>From http://bugs.python.org/issue14156
"argparse.FileType for '-' doesn't work for a mode of 'rb'"
I learned that 'stdin/out' can be embedded in an 'open' by using the 'fileno()' and 'closefd=False' (so it isn't closed at the end of open).
With this, the dummy file context that I implemented in the previous patch, could be replaced with:
partial(open, sys.stdin.fileno(), mode=self._mode,..., closefd=False)
However, as Steven Bethard wrote in the earlier issue, setting up tests when stdin/out will be redirected is not a trivial problem. So I don't yet have a testable patch.
---------------
And just for the record, the 'osaccess' testing that I wrote earlier, probably should also test that proposed output file string is not already a directory.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13824>
_______________________________________
More information about the Python-bugs-list
mailing list