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

2021-07-25 Thread Nils Kattenbeck
Nils Kattenbeck added the comment: A good alternative would be to use pathlib.Path. The only downside would be that one has to manually handle `-` but besides that it solves most problems. Still the fact that file descriptors are kept open should be added as a warning to the docs --

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

2019-08-28 Thread sebix
Change by sebix : -- nosy: +sebix ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mai

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

2019-05-14 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: Hi, Are you interested to write test cases? They could be useful for the fix. Thank you -- nosy: +matrixise ___ Python tracker ___

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

2019-05-10 Thread paul j3
paul j3 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

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

2019-05-07 Thread Mitar
Mitar added the comment: > So it's already possible to do what you describe, simply by doing: I think there is an edge case here if a stdin/stdout is opened? It would get closed at exist from the context, no? So I suggest that a slight extension of what open otherwise returns is returned w

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

2019-05-07 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: For information, issue 33927 is related. I removed one of the FileType from json.tool argument parser to work around this behavior (https://github.com/python/cpython/pull/7865/files#diff-e94945dd18482591faf1e294b029a6afR44). If paul.j3 does not have his patch a

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

2019-05-07 Thread Josh Rosenberg
Josh Rosenberg added the comment: Mitar: argparse.FileType's __call__ (which is what "parses" the argument) returns whatever open (aka io.open) returns. Basically, post-parsing, there is nothing about the result of FileType that distinguishes it from a manually opened file (or when '-' is pa

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

2019-05-06 Thread Mitar
Mitar 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

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

2014-04-01 Thread paul j3
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

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

2013-09-25 Thread paul j3
paul j3 added the comment: An alternative way to delay the file opening, is to return an instance that has a `filename` attribute, and has an `open` method. This can be compactly added to the `FileContext` that I defined in the previous patch. The `FileContext` provides the `_ostest` functio

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

2013-09-23 Thread paul j3
paul j3 added the comment: In this patch I implement a FileContext class. It differs from FileType in 2 key areas: - it returns a 'partial(open, filename, ...)' - it wraps '-' (stdin/out) in a dummy context protecting the file from closure. The resulting argument is meant to be used as: w

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

2013-09-15 Thread paul j3
Changes by paul j3 : -- nosy: +paul.j3 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/

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

2012-07-21 Thread Steven Bethard
Steven Bethard added the comment: So I generally agree that FileType is not what you want for anything but quick scripts that can afford to either leave a file open or to close stdin and/or stdout. However, quick scripts are an important use case for argparse, so I don't think we should get r

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

2012-02-03 Thread David Layton
David Layton added the comment: Eric, checked that the file exists But then you’d run into race conditions. The only sure was to say if a file can be opened is to open it. I think you misunderstand me. I am NOT suggesting that you open and close the file. I am saying that you should not o

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

2012-02-03 Thread Éric Araujo
Éric Araujo added the comment: s/sure was/sure way/ -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://

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

2012-02-03 Thread Éric Araujo
Éric Araujo added the comment: > Additionally, there is no way to prevent FileType from clobbering an existing > file > when used with write mode. I think this deserves its own feature request: now that Python 3.3 has an “exclusive create” mode, argparse.FileType could gain support for it. Wo