[issue19014] Allow memoryview.cast() for empty views

Serhiy Storchaka report at bugs.python.org
Fri Sep 13 22:52:29 CEST 2013


New submission from Serhiy Storchaka:

This is one of most annoying things in Python to me. When you want accept any bytes-like object in you bytes-processing function you need special case empty input.

def foo(data):
    data = memoryview(data)
    if data:
        data = data.cast('B')
    else:
        data = b''

You can't use just memoryview(data).cast('B') because it doesn't work for empty data.

>>> memoryview(b'').cast('b')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: memoryview: cannot cast view with zeros in shape or strides

It would be very nice to allow cast() for empty views.

----------
components: Interpreter Core
messages: 197655
nosy: pitrou, serhiy.storchaka, skrah, teoliphant
priority: normal
severity: normal
status: open
title: Allow memoryview.cast() for empty views
type: enhancement
versions: Python 3.4

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


More information about the Python-bugs-list mailing list