[New-bugs-announce] [issue20404] Delayed exception using non-text encodings with TextIOWrapper

Nick Coghlan report at bugs.python.org
Mon Jan 27 06:01:16 CET 2014

New submission from Nick Coghlan:

TextIOWrapper doesn't check the codec type early the way the convenience methods now do, so the open() method currently still suffers from the problems Victor described in issue 19619 for str.encode() and bytes.decode():

>>> with open("hex.txt", 'w') as f:
...     f.write("aabbccddeeff")
>>> print(open('hex.txt').read())
>>> print(open('hex.txt', encoding='hex').read())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: decoder should return a string result, not 'bytes'

These codecs are never going to work correctly with TextIOWrapper, so we should add the appropriate compatibility check in the constructor.

assignee: ncoghlan
messages: 209396
nosy: haypo, larry, ncoghlan, serhiy.storchaka
priority: release blocker
severity: normal
stage: test needed
status: open
title: Delayed exception using non-text encodings with TextIOWrapper
type: behavior
versions: Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list