Skip to content

Commit e4da289

Browse files
committed
renamed decorator to tagger
1 parent a247b81 commit e4da289

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

examples/formatters.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ def int2word(num, separator="-"):
7575
print("num out of range")
7676

7777

78-
def decorate_row_obj(row_obj: MyRowObject) -> dict:
79-
"""Example row decorator function processing row objects"""
78+
def tag_row_obj(row_obj: MyRowObject) -> dict:
79+
"""Example row tagging function processing row objects and returning
80+
optional properties"""
8081
opts = dict()
8182
if row_obj.field4 % 4 == 0:
8283
opts[tf.TableFormatter.ROW_OPT_TEXT_COLOR] = tf.TableColors.TEXT_COLOR_GREEN
@@ -99,12 +100,12 @@ def decorate_row_obj(row_obj: MyRowObject) -> dict:
99100
tf.Column('Multiplied', obj_formatter=multiply))
100101

101102
print("Formatters on object-based row entries")
102-
print(tf.generate_table(rows, columns, row_decorator=decorate_row_obj))
103+
print(tf.generate_table(rows, columns, row_tagger=tag_row_obj))
103104

104105

105-
def decorate_row_tuples(row_tuple: Tuple) -> dict:
106+
def tag_row_tuples(row_tuple: Tuple) -> dict:
106107
"""
107-
Example decorator function processing row tuples/iterables
108+
Example row tagging function processing row tuples/iterables
108109
109110
Note that this is the tuple as provided to the TableFormatter prior
110111
to display formatting performed on each column
@@ -130,4 +131,4 @@ def decorate_row_tuples(row_tuple: Tuple) -> dict:
130131
tf.Column('Multiplied', obj_formatter=multiply_tuple))
131132

132133
print("Formatters on tuple-based row entries")
133-
print(tf.generate_table(rows, columns, row_decorator=decorate_row_tuples))
134+
print(tf.generate_table(rows, columns, row_tagger=tag_row_tuples))

tableformatter.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,15 @@ def generate_table(rows: Iterable[Union[Iterable, object]],
604604
columns: Collection[Union[str, Tuple[str, dict]]]=None,
605605
grid_style: Optional[Grid]=None,
606606
transpose: bool=False,
607-
row_decorator: Callable=None) -> str:
607+
row_tagger: Callable=None) -> str:
608608
"""
609609
Convenience function to easily generate a table from rows/columns
610610
611611
:param rows: iterable of objects or iterable fields
612612
:param columns: Iterable of column definitions
613613
:param grid_style: The grid style to use
614614
:param transpose: Transpose the rows/columns for display
615-
:param row_decorator: decorator function to apply per-row options
615+
:param row_tagger: decorator function to apply per-row options
616616
:return: formatted string containing the table
617617
"""
618618
show_headers = True
@@ -646,7 +646,7 @@ def generate_table(rows: Iterable[Union[Iterable, object]],
646646
if grid_style is None:
647647
grid_style = DEFAULT_GRID
648648
formatter = TableFormatter(columns, grid_style=grid_style, show_header=show_headers,
649-
use_attribs=use_attrib, transpose=transpose, row_decorator=row_decorator)
649+
use_attribs=use_attrib, transpose=transpose, row_tagger=row_tagger)
650650
return formatter.generate_table(rows)
651651

652652

@@ -763,7 +763,7 @@ def __init__(self,
763763
use_attribs=False,
764764
transpose=False,
765765
row_show_header=False,
766-
row_decorator: Callable=None):
766+
row_tagger: Callable=None):
767767
"""
768768
:param columns: list of either column names or tuples of (column name, dict of column options)
769769
:param cell_padding: number of spaces to pad to the left/right of each column
@@ -789,7 +789,7 @@ def __init__(self,
789789
TableFormatter.TABLE_OPT_TRANSPOSE: transpose,
790790
TableFormatter.TABLE_OPT_ROW_HEADER: row_show_header}
791791
self._show_header = show_header
792-
self._row_decorator = row_decorator
792+
self._row_tagger = row_tagger
793793

794794
for col_index, column in enumerate(columns):
795795
if isinstance(column, tuple) and len(column) > 1 and isinstance(column[1], dict):
@@ -925,12 +925,12 @@ def generate_table(self, entries: Iterable[Union[Iterable, object]], force_trans
925925
except TypeError:
926926
# not iterable, so we just use the object directly
927927
entry_obj = entry
928-
if self._row_decorator is not None:
929-
entry_opts = self._row_decorator(entry_obj)
928+
if self._row_tagger is not None:
929+
entry_opts = self._row_tagger(entry_obj)
930930
else:
931931
entry_obj = entry[0]
932-
if self._row_decorator is not None:
933-
entry_opts = self._row_decorator(entry_obj)
932+
if self._row_tagger is not None:
933+
entry_opts = self._row_tagger(entry_obj)
934934
if len(entry) == 2 and isinstance(entry[1], dict):
935935
entry_opts.update(entry[1])
936936

@@ -966,8 +966,8 @@ def generate_table(self, entries: Iterable[Union[Iterable, object]], force_trans
966966
row.append(field_lines)
967967

968968
else:
969-
if self._row_decorator is not None:
970-
entry_opts = self._row_decorator(entry)
969+
if self._row_tagger is not None:
970+
entry_opts = self._row_tagger(entry)
971971
if len(entry) == len(self._columns) + 1 and isinstance(entry[len(self._columns)], dict):
972972
# if there is exactly 1 more entry than columns, the last one is metadata
973973
entry_opts.update(entry[len(self._columns)])

0 commit comments

Comments
 (0)