Skip to content

Commit

Permalink
Change some errors to TypeErrors
Browse files Browse the repository at this point in the history
Had some `ValueError`s that really should have been `TypeError`s. This
fixes them to properly raise as `TypeError`s.
  • Loading branch information
jakirkham committed Feb 20, 2017
1 parent 9b70f83 commit 0eeb187
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 0eeb187

Please sign in to comment.