Skip to content

Commit

Permalink
Change some ValueErrors to TypeErrors
Browse files Browse the repository at this point in the history
Had some `ValueError`s raised in `reformat_slice`, which really should
have been `TypeError`s. The two cases in particular were unsupported
general type or sequence that contained unsupported elements like
non-integers. This converts them to `TypeError`s instead.
  • Loading branch information
jakirkham committed Feb 20, 2017
1 parent 9b70f83 commit 127b61d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions kenjutsu/format.py
Expand Up @@ -75,7 +75,7 @@ def reformat_slice(a_slice, a_length=None):
new_slice = index_to_slice(a_slice)
elif isinstance(a_slice, collections.Sequence):
if not all(map(lambda i: isinstance(i, numbers.Integral), a_slice)):
raise ValueError(
raise TypeError(
"Arbitrary sequences not permitted."
" All elements must be of integral type."
)
Expand All @@ -86,7 +86,7 @@ def reformat_slice(a_slice, a_length=None):
new_slice.append(reformat_slice(i, a_length))
return new_slice
elif not isinstance(a_slice, slice):
raise ValueError(
raise TypeError(
"Expected a `slice` type. Instead got `%s`." % str(a_slice)
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_format.py
Expand Up @@ -109,7 +109,7 @@ def test_index_to_slice(self):


def test_reformat_slice(self):
with self.assertRaises(ValueError) as e:
with self.assertRaises(TypeError) as e:
format.reformat_slice(None)

self.assertEqual(
Expand All @@ -125,7 +125,7 @@ def test_reformat_slice(self):
"Slice cannot have a step size of `0`."
)

with self.assertRaises(ValueError) as e:
with self.assertRaises(TypeError) as e:
format.reformat_slice([None])

self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_kenjutsu.py
Expand Up @@ -35,7 +35,7 @@ def setUp(self):


def test_reformat_slice(self):
with self.assertRaises(ValueError) as e:
with self.assertRaises(TypeError) as e:
kenjutsu.reformat_slice(None)

self.assertEqual(
Expand All @@ -51,7 +51,7 @@ def test_reformat_slice(self):
"Slice cannot have a step size of `0`."
)

with self.assertRaises(ValueError) as e:
with self.assertRaises(TypeError) as e:
kenjutsu.reformat_slice([None])

self.assertEqual(
Expand Down

0 comments on commit 127b61d

Please sign in to comment.