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 <rep...@bugs.python.org> <http://bugs.python.org/issue19014> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com