Support with statements - #120
Conversation
|
On first glance this doesn't seem to be in line with the intended use of The code in included unit tests doesn't throw any exceptions. Although The example in the README: with TabulateContextManager() as t:
t("Bill", 25)
t("Mary", 26)is roughly equivalent to: try:
rows = []
rows.append("Bill", 25)
rows.append("Mary", 26)
except:
raise
finally:
print(tabulate(rows))I suggest reading through PEP-0343 and reconsidering if the above is really a common use case for users of this library. Is your use case really that on exceptions while adding rows you want to print whatever made its way into the table data and then re-throw exception? Because this is what the code in this PR does, albeit through use of syntactic sugar. If your use case is really this: rows = []
rows.append("Bill", 25)
rows.append("Mary", 26)
print(tabulate(rows))then it is IMHO a use case where there's no need for context management (that array with data in the example can reside in whatever context programmer wants it in, e.g. the scope of a function or in some object) and exception handling (non-existent in the example, so there's nothing for the |
|
TBH I was only looking after the "syntactic sugar" part. I agree with your concerns and that this "feature" is not important. Please feel free to close this PR if you want. |
|
I agree with you that it is feature creep at the moment, and it goes against "Explicit is better than implicit" principle. |
This is a re-implementation of #81
Copying from README: