Skip to content

Commit

Permalink
add type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonthegoon committed Aug 2, 2023
1 parent aa01f64 commit 3b36bfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tablib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ def pop(self):
def get(self, index):
"""Returns the row from the :class:`Dataset` at the given index."""

return self[index]
if isinstance(index, int):
return self[index]

raise TypeError('Row indices must be integers.')

# -------
# Columns
Expand Down
3 changes: 3 additions & 0 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def test_get(self):
with self.assertRaises(IndexError):
self.founders.get(3)

with self.assertRaises(TypeError):
self.founders.get('first_name')

def test_get_col(self):
"""Verify getting columns by index"""

Expand Down

0 comments on commit 3b36bfc

Please sign in to comment.