[issue14156] argparse.FileType for '-' doesn't work for a mode of 'rb'

Josh Rosenberg report at bugs.python.org
Tue May 7 12:18:25 EDT 2019


Josh Rosenberg <shadowranger+python at gmail.com> added the comment:

Serhiy: To be clear, Moritz's patch won't work if stdin/stdout are io.StringIO or the like either, since StringIO lacks a buffer attribute.

Personally, I'm content to:

1. Ignore the closeability of the standard handles; that's not part of this bug, and just introduces more headaches to getting a patch approved (and conceivably breaks back compat if the user *wants* the handle closed even if it's a standard handle). Nothing is made worse by ignoring it after all, just not made better immediately.
2. Ignore the possibility of stdin/stdout without a buffer attribute; it will raise an error, but that's a reasonable response to demanding a binary stream in a scenario where only a text stream is available
3. Not use fileno, as it mostly supports the "anti-close" behavior I dismissed in #1, and has a bunch of pitfalls (e.g. a standard handle rebound to a TextIOWrapper around GzipFile or the like has a fileno attribute, but using it bypasses the compression; basically, you can't consider fileno to be equivalent to the underlying binary stream, because binary streams can be wrapped as well).

I'm going to convert Moritz's proposal to a PR and hope I can get core developer approval for it.

----------

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


More information about the Python-bugs-list mailing list