Skip to content

Commit cdcbe8a

Browse files
committed
Merge pull request #13 from caspervdw/fix-pipeline
FIX Propagation of indexed attributes
2 parents f1511d2 + bbebe8d commit cdcbe8a

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

slicerator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,11 @@ def __getattr__(self, name):
255255
self._propagate_attrs = []
256256
if name in self._propagate_attrs:
257257
attr = getattr(self._ancestor, name)
258-
if hasattr(attr, '_index_flag'):
259-
return SliceableAttribute(self, getattr(self._ancestor, name))
258+
if (isinstance(attr, SliceableAttribute) or
259+
hasattr(attr, '_index_flag')):
260+
return SliceableAttribute(self, attr)
260261
else:
261-
return getattr(self._ancestor, name)
262+
return attr
262263
raise AttributeError
263264

264265
def __getstate__(self):
@@ -452,7 +453,7 @@ def __init__(self, slicerator, attribute):
452453
self._ancestor = slicerator._ancestor
453454
self._len = slicerator._len
454455
self._get = attribute
455-
self._indices = slicerator._indices
456+
self._indices = slicerator.indices # make an independent copy
456457

457458
@property
458459
def indices(self):

tests.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,9 @@ def test_slice_of_slice_of_slice_of_slice():
122122
compare_slice_to_list(slice2, list('cegi'))
123123
slice3 = slice2[:]
124124
compare_slice_to_list(slice3, list('cegi'))
125-
print('define slice4')
126125
slice4 = slice3[:-1]
127-
print('compare slice4')
128126
compare_slice_to_list(slice4, list('ceg'))
129-
print('define slice4a')
130127
slice4a = slice3[::-1]
131-
print('compare slice4a')
132128
compare_slice_to_list(slice4a, list('igec'))
133129

134130

@@ -229,6 +225,7 @@ def close(self):
229225
with assert_raises(AttributeError):
230226
a[:5].nonexistent_attr
231227

228+
compare_slice_to_list(list(a.s), list('ABCDEFGHIJ'))
232229
compare_slice_to_list(list(a[::2].s), list('ACEGI'))
233230
compare_slice_to_list(list(a[::2][1:].s), list('CEGI'))
234231

@@ -243,10 +240,9 @@ def close(self):
243240
with assert_raises(AttributeError):
244241
b[:5].nonexistent_attr
245242

246-
# TODO: propagation of indexed attributes does not work.
247-
# Disable tests for now.
248-
# compare_slice_to_list(list(b[::2].s), list('ACEGI'))
249-
# compare_slice_to_list(list(b[::2][1:].s), list('CEGI'))
243+
compare_slice_to_list(list(b.s), list('ABCDEFGHIJ'))
244+
compare_slice_to_list(list(b[::2].s), list('ACEGI'))
245+
compare_slice_to_list(list(b[::2][1:].s), list('CEGI'))
250246

251247

252248
def test_getattr_subclass():

0 commit comments

Comments
 (0)