Erik Bray added the comment:

I just recently discovered this myself.  In the process of debugging the issue 
I also noticed the same bug that is now fixed via Issue 24402.

While I agree that Issue 24402 mostly mitigates the issue I think this patch is 
still worthwhile, as the current behavior still leads to cryptic, hard to debug 
errors.  For example (although this is not great code, bear with me...) one 
could write a stdout wrapper like:

>>> class WrappedStream:
...     encoding = 'utf8'
...     errors = None
...     def __getattr__(self, attr):
...         return getattr(sys.__stdout__, attr)
... 
>>> sys.stdout = WrappedStream()
>>> sys.stdout.fileno()
1
>>> sys.stdout.isatty()
True
>>> sys.stdout.errors
>>> input('Prompt: ')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad argument type for built-in operation

This still goes down the path for ttys, but because the 'errors' attribute does 
not defer to the underlying stream it still leads to a hard to debug exception. 
 To be clear, I think the above code *should* break, just not as cryptically.

----------
nosy: +erik.bray

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8256>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to