2022 11 10 Python 3.11 Error Reporting
Went to a Python meetup today where the new features in Python 3.11 were discussed. Among them was of course the new nifty error reporting. It was noted that the error reporting does NOT work when using the REPL, but only when running a script through the interpreter.
It wasn’t immediately apparent why that was, so I wanted to do a little bit of digging and see if I could find anything about it. I was browsing Pep 657, when I remembered that each pep has a discussion thread. Linked to the discussion thread was this idea to add the feature from Pep 657 to the REPL. The author of Pep 657 (Pablo Galindo) stated:
This is not a problem of the PEP but how the REPR works. That’s why it was never discussed in the PEP discussion thread or the PEP itself.
The reason this is not supported at the time in the REPL is because the source is not available at the time of the exception. We would need to implement some bigger changes all around to make it available when that happens. Notice that even before 3.11 cpython doesn’t show source information in trace backs.
We played a bit with the idea and tried to propagate source around in code objects and the like but we didn’t like the compromises and the balance of advatanges to maintenance cost, so we never went forward.
So there you have it. The “source” isn’t available, and is needed for this fine-grained error location feature, so it doesn’t work in the REPL.