Sunday, December 20, 2020
Saturday, December 19, 2020
Friday, December 18, 2020
Thursday, December 17, 2020
As I work making Friendly-traceback provide more useful information regarding the cause of an exception, I sometimes encounter weird "corner cases" about either Python itself  or occasionally about pytest . Today, it was pytest's turn to give me a new puzzle to solve.
Consider the following:
If you run this, Python will give you a TypeError: 'float' object cannot be interpreted as an integer
Using Friendly-traceback's console , I get something slightly more informative.
Actually, I can get even more information using "explain()":
Time to add this new working case to the unit test suite. I create a barebone one for the purpose of this blog, without capturing the output and comparing with what is expected.
import friendly_traceback def test(): try: range(1.0) except: friendly_traceback.explain_traceback() if __name__ == '__main__': test()
Here's what happens if I run this using Python:
A new float variable, "start", has suddenly appeared, seemingly out of nowhere. Note that this pytest oddity is not revealed if we use a string instead of a float as the wrong type of argument.
Time to move on to handling other cases ...
 See this blogpost.
 An issue that I filed about a previous case seems to have disappeared and all that remains is this question on Stack Overflow.
 This is my local development version; the example shown here will be handled by versions 0.2.8 and later, to be released on pypi.
Wednesday, December 09, 2020
This is a quick update on the status of Friendly-traceback. As of today, it works with the IPython console, and works even better in a JupyterLab environment.
First, a comparison with using it in the new Windows terminal making use of Rich for syntax highlighting, which is something that has been working for quite a while now.
Next, is the same example in an IPython console, running in a Windows terminal.
I've tried to use Rich to do syntax colouring with the IPython console ... but the result is really disappointing.
Finally, here's what it looks like in the JupyterLab environment.
Right now, it is not possible to select a different theme for syntax highlighting; this will have to wait until later.
To find out more about Friendly-traceback (excluding this new IPython experimental support), please consult the documentation.