Support with statements - #81
Conversation
f7ab40e to
4bef88e
Compare
astanin
left a comment
There was a problem hiding this comment.
I think it's a very cool idea!
But there are some issues I believe have to be addressed:
-
doc-string of the
tabulatefunction is different, so users of the basic function we'll see docs of the context manager first, and then should follow an indirection to figure out how to use tabulate() function. I suggest that the docstring of thetabulate()function stays the same (or is extended). Also, most users should not care/know about underscored names. The function should be usable by whoever learned Python just yesterday. -
Named arguments have been moved to the hidden function
_tabulate(). I'm not sure how it will play out with autocomplete in various environments. Named arguments are usually picked up and suggested automatically. Did you test how it works with autocomplete somewhere? -
Existing tests have been changed. In particular
test_no_data(). This is a breaking change which can be avoided.
If you're still interested, I'll accept this feature if you can address these comlaints: 1) keep tabulate() as the top-level function (feel free to give another name to the context manager, e.g. tabulate_context); 2) keep tabulate docstring and its named arguments; 3) do not change existing tests.
4bef88e to
b2c26bc
Compare
This converts
tabulateto a context manager.If called as before, it will work as before. However, if the first argument (
tabular_data) isn't provided, it will act as a contextmanager, the "as" value being a function that adds values to the table being formatted:
should be equivalent to:
The rest of the arguments should work with the 'with' syntax as well:
The differences when using the 'with' syntax are:
printheadersetc) cannot be provided as positional arguments, only as keyword arguments