[New-bugs-announce] [issue22884] argparse.FileType.__call__ returns unwrapped sys.stdin and stdout

Kevin Orr report at bugs.python.org
Sun Nov 16 15:58:06 CET 2014


New submission from Kevin Orr:

When one uses a file object returned by `FileType.__call__` as a context manager, `sys.stdin`'s or `sys.stdout`'s `__exit__` will be triggered upon exit of the context, in turn calling their `close` method.

Perhaps the issue is that `sys.stdin` and `sys.stdout` have poor `__exit__` methods, but my proposal (and it's not a particularly clean one) is to override the file object's `__exit__` if it happens to be either `sys.stdin` or `sys.stdout` to simply return True when called.

----------
components: Library (Lib)
messages: 231249
nosy: keviv
priority: normal
severity: normal
status: open
title: argparse.FileType.__call__ returns unwrapped sys.stdin and stdout
type: behavior
versions: Python 2.7, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22884>
_______________________________________


More information about the New-bugs-announce mailing list