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

Serhiy Storchaka report at bugs.python.org
Thu Feb 2 08:11:38 EST 2017


Serhiy Storchaka added the comment:

> - maybe the bug is that python2 should not reject integers, making the upgrade path to python3 (or the backward compatibility with python2, same thing) easy.

It is too late for this.

You can use the helper that converts the argument to appropriate depending on the version.

if PY2:
    def helper(arg):
        if isinstance(ar, (int, long)):
            return chr(arg)
        return arg
else:
    def helper(arg):
        return arg
...
v[0] = helper(42)

Or just have different branches for performance critical code:

if PY2:
    v[0] = b'\x2a'
else:
    v[0] = 42

I don't think Python interpreter should be changed here.

----------
nosy: +serhiy.storchaka

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


More information about the Python-bugs-list mailing list