[New-bugs-announce] [issue29404] "TypeError: 'int' does not have the buffer interface" on memoryview over bytearray

Vincent Pelletier report at bugs.python.org
Tue Jan 31 19:00:11 EST 2017


New submission from Vincent Pelletier:

Quoting a github gist[1] (not mine, I found it while googling for this error) clearly illustrating the issue:

# Python 2
>>> b = bytearray(8)
>>> v = memoryview(b)
>>> v[0] = 42
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' does not have the buffer interface
>>> b
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')

# Python 3
>>> b = bytearray(8)
>>> v = memoryview(b)
>>> v[0] = 42
>>> b
bytearray(b'*\x00\x00\x00\x00\x00\x00\x00')

This is especially annoying as on python3 bytearray.__setitem__ only accepts integers, making working py2 code totally incompatible with py3 in a 2to3-undetectable way.

[1] https://gist.github.com/superbobry/b90c0cc7c44beaa51ef9

----------
messages: 286567
nosy: vpelletier
priority: normal
severity: normal
status: open
title: "TypeError: 'int' does not have the buffer interface" on memoryview over bytearray
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29404>
_______________________________________


More information about the New-bugs-announce mailing list