From 7d551437221cb92632f0a5a48bf658ecd2e3252c Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 20 Dec 2023 08:34:36 +0100 Subject: [PATCH] Apply suggestions from Hugo's code review Co-authored-by: Hugo van Kemenade --- src/tablib/core.py | 8 ++++---- tests/test_tablib.py | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tablib/core.py b/src/tablib/core.py index 9010c0ad..ea03dba6 100644 --- a/src/tablib/core.py +++ b/src/tablib/core.py @@ -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') @@ -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 @@ -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)) @@ -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) diff --git a/tests/test_tablib.py b/tests/test_tablib.py index 7d33f11d..39ead84b 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -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(