[New-bugs-announce] [issue32110] Make codecs.StreamReader.read() more compatible with read() of other files

Serhiy Storchaka report at bugs.python.org
Wed Nov 22 02:40:16 EST 2017


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

Usually the read() method of a file-like object takes one optional argument which limits the amount of data (the number of bytes or characters) returned if specified.

codecs.StreamReader.read() also has such parameter. But this is the second parameter. The first parameter limits the number of bytes read for decoding. read(1) can return 70 characters, that will confuse most callers which expect either a single character or an empty string (at the end of stream).

Some times ago codecs.open() was recommended as a replacement for the builtin open() in programs that should work in 2.x and 3.x (this was before adding io.open()), and it is still used in many programs. But this peculiarity makes it bad replacement of builtin open().

I wanted to fix this issue long time ago, but forgot, and the question on Stack Overflow has reminded me about this. https://stackoverflow.com/questions/46437761/codecs-openutf-8-fails-to-read-plain-ascii-file

----------
assignee: serhiy.storchaka
components: IO, Library (Lib)
messages: 306701
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Make codecs.StreamReader.read() more compatible with read() of other files
type: behavior
versions: Python 2.7, Python 3.6, Python 3.7

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


More information about the New-bugs-announce mailing list