Objective of pybettererror:
Repetitiveness create the need of automation.
I was always opening module and scrolling to the exceptions causing statement. Loosing precious time trying to find the write line of code where it all starts. Thats where i thought an Hyperlink on the traceback would save lots of time, and increase productivity.
The means to do what we need
Python is made to be updated and customize. You can read almost every line of code of it. You can improve on it, even if it's not easy to find something to complain about. But, once in a while, a good idea make it's way up the lather. This is one of them
Create Hyperlinks to the file line number with the traceback data sent by the debugger to the output window.
Replacing sys.stderr.write by a custom method.
How does it work?
Transformation made by pybettererror in the sys module
Actualy, the transformation is made deep in the core of the existing shell active instance. When a program is executed, all information printed or inputed pass by the shell window, unless redirected by the programme or the user. This is exactly what this module is doing.
How to intercept the debugger traceback messages?
There is, in the sys module, an instance named sys.stderr, it is made to receve all message from the python debuger. It send those message to the output window with the proper coloring tags. The debuger send is message to the command sys.stderr.write and the standard error (sys.stderr) send it to the output text widget with the error tags.
To intercept those message, there is just to replace the sys.stderr.write method by a custom method. We still need to print the message sent by the debuger, so we can see what is going on. But we can reformat and parce the informations in the same time.
Now the messages
Normally, those message are returned to the output window with you own tags. (idlelib.PyShell.flist.pyshell.write) But you can also print those lines into any object, container or widget.
This is where i got the idea to create hyperlinks with those traceback file and line numbers sent by the debugger. It was an genious idea! I needed to share it with everyone.