[Python-Dev] Why does _pyio.*.readinto have to work with 'b' arrays? (original) (raw)

Nikolaus Rath Nikolaus at rath.org
Sun Jun 15 21:05:09 CEST 2014


Victor Stinner <victor.stinner at gmail.com> writes:

Le 15 juin 2014 02:42, "Benjamin Peterson" <benjamin at python.org> a écrit :

On Sat, Jun 14, 2014, at 15:39, Nikolaus Rath wrote: > It seems to me that a much cleaner solution would be to simply declare > pyio's readinto to only work with bytearrays, and to explicitly raise a > (more helpful) TypeError if anything else is passed in.

That seems reasonable. I don't think pyio's behavior is terribly important compared to the C io module. Which types are accepted by the readinto() method of the C io module?

Everything implementing the buffer protocol.

If the C module only accepts bytearray, the array hack must be removed from pyio.

_pyio currently accepts only bytearray and 'b'-type arrays. But it seems with memoryview.cast() we now have a way to make it behave like the C module.

Best, -Nikolaus

GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

         »Time flies like an arrow, fruit flies like a Banana.«


More information about the Python-Dev mailing list