Skip to content

Commit

Permalink
Apply suggestions from Hugo's code review
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo van Kemenade <[email protected]>
  • Loading branch information
claudep and hugovk authored Dec 20, 2023
1 parent 55fd5d2 commit 7d55143
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/tablib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, *args, **kwargs):
self._formatters = []

# {col_index: col_func}
self._dyn_columns = {}
self._dynamic_columns = {}

self.headers = kwargs.get('headers')

Expand Down Expand Up @@ -241,7 +241,7 @@ def _set_in_format(self, fmt_key, in_stream, **kwargs):
def _validate(self, row=None, col=None, safety=False):
"""Assures size of every row in dataset is of proper proportions."""
if row:
is_valid = (len(row) == (self.width - len(self._dyn_columns))) if self.width else True
is_valid = (len(row) == (self.width - len(self._dynamic_columns))) if self.width else True
elif col:
if len(col) < 1:
is_valid = True
Expand Down Expand Up @@ -452,7 +452,7 @@ def insert(self, index, row, tags=()):
"""

self._validate(row)
for pos, func in self._dyn_columns.items():
for pos, func in self._dynamic_columns.items():
row = list(row)
row.insert(pos, func(row))
self._data.insert(index, Row(row, tags=tags))
Expand Down Expand Up @@ -553,7 +553,7 @@ def insert_col(self, index, col=None, header=None):

# Callable Columns...
if hasattr(col, '__call__'):
self._dyn_columns[self.width] = col
self._dynamic_columns[self.width] = col
col = list(map(col, self._data))

col = self._clean_col(col)
Expand Down
1 change: 1 addition & 0 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def new_col(x):
return x[0]

self.founders.append_col(new_col, header='first_again')

# A new row can still be appended, and the dynamic column value generated.
self.founders.append(('Some', 'One', 71))
self.assertEqual(
Expand Down

0 comments on commit 7d55143

Please sign in to comment.