Skip to content

Commit

Permalink
Restrict to one integral sequence per slice
Browse files Browse the repository at this point in the history
There are a lot of subtle cases when support multiple integral
sequences, which we are not currently supporting correctly. So as to
avoid potentially providing an incorrect result, simply raise an
exception if multiple integral sequences show up in a slices and note
that only one is supported in a slice. Hopefully we can fix this and
relaxing this constraint in the future.
  • Loading branch information
jakirkham committed Feb 17, 2017
1 parent 4fcb0c8 commit b1677a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kenjutsu/format.py
Expand Up @@ -282,4 +282,13 @@ def reformat_slices(slices, lengths=None):

new_slices = tuple(new_slices)

n_seqs = sum(map(
lambda i: isinstance(i, collections.Sequence), new_slices
))
if n_seqs > 1:
raise ValueError(
"Only one integral sequence supported."
" Instead got `%s`." % str(n_seqs)
)

return(new_slices)
10 changes: 10 additions & 0 deletions tests/test_format.py
Expand Up @@ -298,6 +298,16 @@ def test_reformat_slices(self):
"Only one Ellipsis is permitted. Found multiple."
)

with self.assertRaises(ValueError) as e:
format.reformat_slices(
([0, 1], [0, 1]),
)

self.assertEqual(
str(e.exception),
"Only one integral sequence supported. Instead got `2`."
)

rf_slice = format.reformat_slices(slice(None))
self.assertEqual(
rf_slice,
Expand Down

0 comments on commit b1677a0

Please sign in to comment.