Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2cf20e

Browse files
committed
Remove the simple slicing API. All slicing is now done with slice objects.
1 parent 582b586 commit d2cf20e

32 files changed

Lines changed: 79 additions & 811 deletions

Include/object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ typedef struct {
252252
binaryfunc sq_concat;
253253
ssizeargfunc sq_repeat;
254254
ssizeargfunc sq_item;
255-
ssizessizeargfunc sq_slice;
255+
void *was_sq_slice;
256256
ssizeobjargproc sq_ass_item;
257-
ssizessizeobjargproc sq_ass_slice;
257+
void *was_sq_ass_slice;
258258
objobjproc sq_contains;
259259

260260
binaryfunc sq_inplace_concat;

Include/opcode.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ extern "C" {
3636
#define INPLACE_FLOOR_DIVIDE 28
3737
#define INPLACE_TRUE_DIVIDE 29
3838

39-
#define SLICE 30
40-
/* Also uses 31-33 */
41-
42-
#define STORE_SLICE 40
43-
/* Also uses 41-43 */
44-
45-
#define DELETE_SLICE 50
46-
/* Also uses 51-53 */
47-
4839
#define INPLACE_ADD 55
4940
#define INPLACE_SUBTRACT 56
5041
#define INPLACE_MULTIPLY 57

Lib/UserList.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,6 @@ def __len__(self): return len(self.data)
2828
def __getitem__(self, i): return self.data[i]
2929
def __setitem__(self, i, item): self.data[i] = item
3030
def __delitem__(self, i): del self.data[i]
31-
def __getslice__(self, i, j):
32-
i = max(i, 0); j = max(j, 0)
33-
return self.__class__(self.data[i:j])
34-
def __setslice__(self, i, j, other):
35-
i = max(i, 0); j = max(j, 0)
36-
if isinstance(other, UserList):
37-
self.data[i:j] = other.data
38-
elif isinstance(other, type(self.data)):
39-
self.data[i:j] = other
40-
else:
41-
self.data[i:j] = list(other)
42-
def __delslice__(self, i, j):
43-
i = max(i, 0); j = max(j, 0)
44-
del self.data[i:j]
4531
def __add__(self, other):
4632
if isinstance(other, UserList):
4733
return self.__class__(self.data + other.data)

Lib/UserString.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ def __contains__(self, char):
6363

6464
def __len__(self): return len(self.data)
6565
def __getitem__(self, index): return self.__class__(self.data[index])
66-
def __getslice__(self, start, end):
67-
start = max(start, 0); end = max(end, 0)
68-
return self.__class__(self.data[start:end])
69-
7066
def __add__(self, other):
7167
if isinstance(other, UserString):
7268
return self.__class__(self.data + other.data)
@@ -220,17 +216,6 @@ def __delitem__(self, index):
220216
index += len(self.data)
221217
if index < 0 or index >= len(self.data): raise IndexError
222218
self.data = self.data[:index] + self.data[index+1:]
223-
def __setslice__(self, start, end, sub):
224-
start = max(start, 0); end = max(end, 0)
225-
if isinstance(sub, UserString):
226-
self.data = self.data[:start]+sub.data+self.data[end:]
227-
elif isinstance(sub, basestring):
228-
self.data = self.data[:start]+sub+self.data[end:]
229-
else:
230-
self.data = self.data[:start]+str(sub)+self.data[end:]
231-
def __delslice__(self, start, end):
232-
start = max(start, 0); end = max(end, 0)
233-
self.data = self.data[:start] + self.data[end:]
234219
def immutable(self):
235220
return UserString(self.data)
236221
def __iadd__(self, other):

Lib/opcode.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,6 @@ def jabs_op(name, op):
7070
def_op('BINARY_TRUE_DIVIDE', 27)
7171
def_op('INPLACE_FLOOR_DIVIDE', 28)
7272
def_op('INPLACE_TRUE_DIVIDE', 29)
73-
def_op('SLICE+0', 30)
74-
def_op('SLICE+1', 31)
75-
def_op('SLICE+2', 32)
76-
def_op('SLICE+3', 33)
77-
78-
def_op('STORE_SLICE+0', 40)
79-
def_op('STORE_SLICE+1', 41)
80-
def_op('STORE_SLICE+2', 42)
81-
def_op('STORE_SLICE+3', 43)
82-
83-
def_op('DELETE_SLICE+0', 50)
84-
def_op('DELETE_SLICE+1', 51)
85-
def_op('DELETE_SLICE+2', 52)
86-
def_op('DELETE_SLICE+3', 53)
8773

8874
def_op('INPLACE_ADD', 55)
8975
def_op('INPLACE_SUBTRACT', 56)

Lib/sre_parse.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ def __getitem__(self, index):
139139
return self.data[index]
140140
def __setitem__(self, index, code):
141141
self.data[index] = code
142-
def __getslice__(self, start, stop):
143-
return SubPattern(self.pattern, self.data[start:stop])
144142
def insert(self, index, code):
145143
self.data.insert(index, code)
146144
def append(self, code):

Lib/test/list_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ def test_setslice(self):
178178
a[:] = tuple(range(10))
179179
self.assertEqual(a, self.type2test(range(10)))
180180

181-
self.assertRaises(TypeError, a.__setslice__, 0, 1, 5)
182181
self.assertRaises(TypeError, a.__setitem__, slice(0, 1, 5))
183182

184-
self.assertRaises(TypeError, a.__setslice__)
185183
self.assertRaises(TypeError, a.__setitem__)
186184

187185
def test_delslice(self):

Lib/test/seq_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ def test_getslice(self):
196196
self.assertEqual(a[ -pow(2,128): 3 ], self.type2test([0,1,2]))
197197
self.assertEqual(a[ 3: pow(2,145) ], self.type2test([3,4]))
198198

199-
self.assertRaises(TypeError, u.__getslice__)
200-
201199
def test_contains(self):
202200
u = self.type2test([0, 1, 2])
203201
for i in u:

Lib/test/string_tests.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -939,17 +939,17 @@ def test_subscript(self):
939939
self.checkraises(TypeError, 'abc', '__getitem__', 'def')
940940

941941
def test_slice(self):
942-
self.checkequal('abc', 'abc', '__getslice__', 0, 1000)
943-
self.checkequal('abc', 'abc', '__getslice__', 0, 3)
944-
self.checkequal('ab', 'abc', '__getslice__', 0, 2)
945-
self.checkequal('bc', 'abc', '__getslice__', 1, 3)
946-
self.checkequal('b', 'abc', '__getslice__', 1, 2)
947-
self.checkequal('', 'abc', '__getslice__', 2, 2)
948-
self.checkequal('', 'abc', '__getslice__', 1000, 1000)
949-
self.checkequal('', 'abc', '__getslice__', 2000, 1000)
950-
self.checkequal('', 'abc', '__getslice__', 2, 1)
951-
952-
self.checkraises(TypeError, 'abc', '__getslice__', 'def')
942+
self.checkequal('abc', 'abc', '__getitem__', slice(0, 1000))
943+
self.checkequal('abc', 'abc', '__getitem__', slice(0, 3))
944+
self.checkequal('ab', 'abc', '__getitem__', slice(0, 2))
945+
self.checkequal('bc', 'abc', '__getitem__', slice(1, 3))
946+
self.checkequal('b', 'abc', '__getitem__', slice(1, 2))
947+
self.checkequal('', 'abc', '__getitem__', slice(2, 2))
948+
self.checkequal('', 'abc', '__getitem__', slice(1000, 1000))
949+
self.checkequal('', 'abc', '__getitem__', slice(2000, 1000))
950+
self.checkequal('', 'abc', '__getitem__', slice(2, 1))
951+
952+
self.checkraises(TypeError, 'abc', '__getitem__', 'def')
953953

954954
def test_extended_getslice(self):
955955
# Test extended slicing by comparing with list slicing.

Lib/test/test_array.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,10 @@ def test_setslice(self):
562562
)
563563

564564
a = array.array(self.typecode, self.example)
565-
self.assertRaises(TypeError, a.__setslice__, 0, 0, None)
566565
self.assertRaises(TypeError, a.__setitem__, slice(0, 0), None)
567566
self.assertRaises(TypeError, a.__setitem__, slice(0, 1), None)
568567

569568
b = array.array(self.badtypecode())
570-
self.assertRaises(TypeError, a.__setslice__, 0, 0, b)
571569
self.assertRaises(TypeError, a.__setitem__, slice(0, 0), b)
572570
self.assertRaises(TypeError, a.__setitem__, slice(0, 1), b)
573571

0 commit comments

Comments
 (0)