[issue22884] argparse.FileType.__call__ returns unwrapped sys.stdin and stdout

2014-11-16 Thread Kevin Orr

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 rep...@bugs.python.org
http://bugs.python.org/issue22884
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22884] argparse.FileType.__call__ returns unwrapped sys.stdin and stdout

2014-11-16 Thread Kevin Orr

Kevin Orr added the comment:

Hmm, not sure why I thought I needed `inline code formatting`. It's all 
monospace anyway!

Anyway, I'm thinking that adding this somewhere in argparse.py:

class _WrappedIO(object):
def __init__(self, fileobj):
self._file = fileobj

def __exit__(tp, val, tb):
return True

def __getattr__(self, name):
return self._file.__gettattr__(name)

and then applying the attached patch *may* fix this.

--
keywords: +patch
Added file: http://bugs.python.org/file37209/argparse.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22884
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com