Conversation
…be chained together. This allows an value generated by an object formatter to be passed to an existing display formatter function. For example, this allows a computed float value to from an object formatter to go through a display formatter to round/truncate digits.
… to return the per-row options. Currently the only supported option is text color
tleonhardt
left a comment
There was a problem hiding this comment.
This is a very helpful API change and the code looks fine.
I definitely recommend changing the usage of the term "decorator" to something like "stylist" since it isn't consistent with what is meant by a decorator in Python (though it is fully consistent with the GoF design pattern).
| print("num out of range") | ||
|
|
||
|
|
||
| def decorate_row_obj(row_obj: MyRowObject) -> dict: |
There was a problem hiding this comment.
I grok that you are applying the object-oriented decorator pattern here, however in Python the term decorator has a very specific meaning.
In Python, a decorator is a function which takes another function as an argument and extends the behavior of that latter function without explicitly modifying it because it returns the modified function:
def a_decorator(func: Callable) -> Callable:
"""Do something here to modify func and return the modified version"""Given that your "decorator" functions are not Python decorators, I would very strongly suggest calling them something else to avoid confusing end users.
This comment applies throughout this PR.
Hmm... how about "stylist" or "style" (depending on grammatical usage) as a synonym which accurately reflects their intent?
| columns: Collection[Union[str, Tuple[str, dict]]]=None, | ||
| grid_style: Optional[Grid]=None, | ||
| transpose: bool=False, | ||
| row_decorator: Callable=None) -> str: |
There was a problem hiding this comment.
So here we could have row_stylist, for example ...
|
|
||
|
|
||
| def Row(*args, text_color: TableColors=None): | ||
| def Row(*args, text_color: Union[TableColors, str]=None): |
There was a problem hiding this comment.
You might want to elaborate in the docstring what kind of str might get passed in for text_color - i.e. it can take ANSI escape codes, but isn't looking for something like 'green'.
Codecov Report
@@ Coverage Diff @@
## master #16 +/- ##
==========================================
- Coverage 88.27% 88.05% -0.23%
==========================================
Files 1 1
Lines 819 829 +10
==========================================
+ Hits 723 730 +7
- Misses 96 99 +3
Continue to review full report at Codecov.
|
| columns: Collection[Union[str, Tuple[str, dict]]]=None, | ||
| grid_style: Optional[Grid]=None, | ||
| transpose: bool=False, | ||
| row_tagger: Callable=None) -> str: |
There was a problem hiding this comment.
The new name works for me. Thanks for the change.
row_decorator function can now be provided to tableformatter to colorize row text
column obj_formatter and formatter can now be chained together to do column data processing prior to column display formatting.