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 2011年07月21日 22:31 by py.user, last changed 2022年04月11日 14:57 by admin.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| slice_del.diff | siegfried.gevatter, 2015年04月13日 14:08 | Patch | review | |
| slice_del.diff | siegfried.gevatter, 2015年04月13日 14:13 | patch including doc change | review | |
| slice_del.diff | siegfried.gevatter, 2015年04月13日 16:49 | review | ||
| slice_del.diff | siegfried.gevatter, 2015年04月13日 16:54 | simplified test | review | |
| slice_del.diff | siegfried.gevatter, 2015年04月13日 17:54 | version without double type cast | review | |
| Messages (9) | |||
|---|---|---|---|
| msg140832 - (view) | Author: py.user (py.user) * | Date: 2011年07月21日 22:31 | |
>>> barr = bytearray(b'abcde')
>>> lst = list('abcde')
>>> barr[::-3] = ()
>>> barr
bytearray(b'acd')
>>> lst[::-3] = ()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: attempt to assign sequence of size 0 to extended slice of size 2
>>> del lst[::-3]
>>> lst
['a', 'c', 'd']
>>>
lst[::-3] = () - is more convenient way for deletion
|
|||
| msg140835 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2011年07月21日 23:18 | |
I happen to prefer del myself, but I agree that the two mutable sequence classes should behave the same. The manual 4.6.4 says s[i:j:k] = t the elements of s[i:j:k] are replaced by those of t (1) 1. t must have the same length as the slice it is replacing. So the list behavior is not a bug. Extending its behavior is a feature request that could only happen in the 'next' release, now 3.3. It is not usually considered a bug for something to do something beyond what is promised; in any case, you are *not* requesting that bytearrays be restricted as lists are. But that could be the fix to remove the 'bug' of inconsistency. That also could not happen until a next release. Since deletion of contiguous slices works and since deletion of extended slices can work and since I found the restriction slightly surprising, I am in favor of extending list behavior unless there is some internal reason why it cannot be. The rationale for the restriction is that replacing a contiguous slice with a different number of items makes sense but replacing non-contiguous items with a different number does not -- except in the special case where the number is 0. So what you are really asking is that the footnote be changed to 1. t must have the same length as the slice it is replacing or be empty That is the current behavior of bytearrays. |
|||
| msg140845 - (view) | Author: py.user (py.user) * | Date: 2011年07月22日 00:22 | |
> I happen to prefer del myself
> but I agree that the two mutable sequence classes should behave the same.
del is not so flexible as assignement
>>> cmpr = [bytearray(i.encode('ascii')) for i in ('abcd', 'efgh', 'ijkl')]
>>> cmpr
[bytearray(b'abcd'), bytearray(b'efgh'), bytearray(b'ijkl')]
>>> cmpr[0][::-2] = cmpr[1][::2] = cmpr[2][1::2] = ()
>>> cmpr
[bytearray(b'ac'), bytearray(b'fh'), bytearray(b'ik')]
>>>
|
|||
| msg140846 - (view) | Author: py.user (py.user) * | Date: 2011年07月22日 00:29 | |
the former could be like: del cmpr[0][::-2], cmpr[1][::2], cmpr[2][1::2] it's ok how to implement this with del ? >>> cmpr [bytearray(b'abcd'), bytearray(b'efgh'), bytearray(b'ijkl')] >>> cmpr[0][::-2], cmpr[1][::2] = (), cmpr[2][1::2] >>> cmpr [bytearray(b'ac'), bytearray(b'jflh'), bytearray(b'ijkl')] >>> |
|||
| msg240586 - (view) | Author: Siegfried Gevatter (siegfried.gevatter) | Date: 2015年04月13日 02:32 | |
I'll have a try at this one. |
|||
| msg240635 - (view) | Author: Thomas Wouters (twouters) * (Python committer) | Date: 2015年04月13日 15:58 | |
I left some style comments in the rietveld review. However, a bigger questions is whether we should change list at all. I think we should; the change is fairly straightforward, there is some value in it and it's a good idea to keep bytearray and other mutable sequences behave similarly (and we can't remove the support from bytearray for obvious backward compatibility reasons.) |
|||
| msg241605 - (view) | Author: Siegfried Gevatter (siegfried.gevatter) | Date: 2015年04月20日 05:27 | |
Thomas, could you take another look? I did update the patch. Thanks! :) |
|||
| msg257341 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年01月02日 10:04 | |
Note that adding this new feature to list adds a pressure to add this feature to other mutable sequences (deque, ElementTree.Element, etc). This is a burden for maintainers. array already supports this feature as well as bytearray. It may be a difference between arrays of unboxed values and general collections of Python objects. |
|||
| msg257407 - (view) | Author: py.user (py.user) * | Date: 2016年01月03日 09:27 | |
Also memoryview() doesn't support: >>> m = memoryview(bytearray(b'abcde')) >>> m[::2] = () Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' does not support the buffer interface >>> m[::2] = b'' Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: memoryview assignment: lvalue and rvalue have different structures >>> m[::2] = b'123' >>> m.tobytes() b'1b2d3' >>> |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:19 | admin | set | github: 56815 |
| 2016年01月03日 09:27:27 | py.user | set | messages: + msg257407 |
| 2016年01月02日 10:43:23 | petri.lehtinen | set | nosy:
- petri.lehtinen |
| 2016年01月02日 10:04:23 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg257341 |
| 2016年01月02日 09:05:45 | ezio.melotti | set | versions: + Python 3.6 |
| 2015年04月20日 20:45:28 | terry.reedy | set | stage: test needed -> patch review versions: + Python 3.5, - Python 3.4 |
| 2015年04月20日 05:27:21 | siegfried.gevatter | set | messages: + msg241605 |
| 2015年04月13日 17:54:08 | siegfried.gevatter | set | files: + slice_del.diff |
| 2015年04月13日 16:54:32 | siegfried.gevatter | set | files: + slice_del.diff |
| 2015年04月13日 16:49:55 | siegfried.gevatter | set | files: + slice_del.diff |
| 2015年04月13日 15:58:48 | twouters | set | nosy:
+ twouters messages: + msg240635 |
| 2015年04月13日 14:13:20 | siegfried.gevatter | set | files: + slice_del.diff |
| 2015年04月13日 14:08:36 | siegfried.gevatter | set | files:
+ slice_del.diff keywords: + patch |
| 2015年04月13日 02:32:16 | siegfried.gevatter | set | nosy:
+ siegfried.gevatter messages: + msg240586 |
| 2013年07月07日 13:37:06 | ezio.melotti | set | nosy:
+ ezio.melotti versions: + Python 3.4, - Python 3.3 |
| 2011年07月22日 18:07:51 | petri.lehtinen | set | nosy:
+ petri.lehtinen |
| 2011年07月22日 00:29:53 | py.user | set | messages: + msg140846 |
| 2011年07月22日 00:22:44 | py.user | set | messages: + msg140845 |
| 2011年07月21日 23:18:44 | terry.reedy | set | versions:
+ Python 3.3, - Python 3.1 nosy: + terry.reedy messages: + msg140835 type: behavior -> enhancement stage: test needed |
| 2011年07月21日 22:31:34 | py.user | create | |