This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年09月13日 20:52 by serhiy.storchaka, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| zerocast.patch | pitrou, 2013年09月13日 21:34 | review | ||
| Messages (10) | |||
|---|---|---|---|
| msg197655 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年09月13日 20:52 | |
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.
|
|||
| msg197659 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年09月13日 20:55 | |
This actually sounds like a bug to me. A view over the empty bytestring is a one-dimensional zero-length view, it isn't a special kind of entity. |
|||
| msg197662 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年09月13日 21:07 | |
Cool. Therefore I can hope on fixing this in maintained releases? |
|||
| msg197663 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年09月13日 21:10 | |
> Cool. Therefore I can hope on fixing this in maintained releases? Provided someone makes a patch :-) |
|||
| msg197666 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年09月13日 21:34 | |
Here is a patch. I can't tell whether it's right for sure, since the whole buffer thing has become so complicated. |
|||
| msg197759 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2013年09月15日 09:55 | |
I agree that this cast should work. Perhaps disallowing zero strides is enough -- I have to look at this more closely though. |
|||
| msg198890 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2013年10月03日 11:32 | |
Ok, I think the main reason for disallowing zeros in view->shape here
was that casts are undefined if also the "shape" argument is given:
x = memoryview(b'')
x.cast('d', shape=[1])
Now, this case *is* already caught at a later stage, since there isn't
enough space for the cast. Nevertheless, the code is tricky, so I'd
prefer to be conservative and catch shape arguments earlier.
I left a suggestion in Rietveld. I would commit it myself, but I'm
moving and my infrastructure is a mess. It would be great if one
of you could take this one.
I'll try to review the general case for ndim > 1 later, but that's
not particularly important right now.
|
|||
| msg198903 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2013年10月03日 17:59 | |
New changeset b08e092df155 by Antoine Pitrou in branch '3.3': Issue #19014: memoryview.cast() is now allowed on zero-length views. http://hg.python.org/cpython/rev/b08e092df155 New changeset 1e13a58c1b92 by Antoine Pitrou in branch 'default': Issue #19014: memoryview.cast() is now allowed on zero-length views. http://hg.python.org/cpython/rev/1e13a58c1b92 |
|||
| msg198904 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年10月03日 18:02 | |
Applied Stefan's suggestion. Thanks for the review :) |
|||
| msg198905 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年10月03日 18:26 | |
Thank you Antoine. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:50 | admin | set | github: 63214 |
| 2013年10月03日 18:26:51 | serhiy.storchaka | set | messages: + msg198905 |
| 2013年10月03日 18:02:37 | pitrou | set | status: open -> closed resolution: fixed messages: + msg198904 stage: needs patch -> resolved |
| 2013年10月03日 17:59:02 | python-dev | set | nosy:
+ python-dev messages: + msg198903 |
| 2013年10月03日 11:32:59 | skrah | set | messages: + msg198890 |
| 2013年10月02日 12:54:56 | ncoghlan | unlink | issue17839 dependencies |
| 2013年10月01日 21:48:18 | serhiy.storchaka | link | issue17839 dependencies |
| 2013年09月15日 09:55:52 | skrah | set | messages: + msg197759 |
| 2013年09月13日 21:34:51 | pitrou | set | files:
+ zerocast.patch keywords: + patch messages: + msg197666 |
| 2013年09月13日 21:10:10 | pitrou | set | messages: + msg197663 |
| 2013年09月13日 21:07:50 | serhiy.storchaka | set | messages: + msg197662 |
| 2013年09月13日 20:55:34 | pitrou | set | versions:
+ Python 3.3 nosy: + ncoghlan messages: + msg197659 type: enhancement -> behavior stage: needs patch |
| 2013年09月13日 20:52:29 | serhiy.storchaka | create | |