[issue13824] argparse.FileType opens a file and never closes it
paul j3
report at bugs.python.org
Fri May 10 23:02:50 EDT 2019
paul j3 <ajipanca at gmail.com> added the comment:
While I continue to follow argparse issues, I'm not doing development (with my own repository, etc).
I haven't revisited the issue since 2013, and don't know that much more about Python file handling. Occasionally 'FileType' issues come up on StackOverflow, and my most common suggestion is accept a string, and open the file yourself.
In writing a solution, keep backward compatibility foremost in mind. We don't want to mess things up for existing code. And keep FileType simple, consistent with Steven's original intent - as a tool for simple input/output scripts.
As for the idea of
2 - Making the argument namespace itself support context management
someone could experiment with a new Namespace class with the proper enter/exit methods. The use of a custom Namespace class is documented
https://docs.python.org/3/library/argparse.html#the-namespace-object
So the idea can be implemented and thoroughly tested without altering the default Namespace class and its use. (With one caution, subparsers won't use this custom class.)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue13824>
_______________________________________
More information about the Python-bugs-list
mailing list