aroberge / friendly

Aimed at Python beginners: replacing standard traceback by something easier to understand
https://friendly-traceback.github.io/docs/index.html
MIT License
325 stars 9 forks source link

Using new information for SyntaxError for Python 3.10 #213

Closed aroberge closed 3 years ago

aroberge commented 3 years ago

SyntaxErrors now include new arguments indicating the end of a range; the full arguments are

e.msg, e.lineno, e.offset, e.end_lineno, e.end_offset

The offset attribute can now point to a location prior to that pointed at in previous Python version - where a single position (line, column) was shown instead of a range, highlighting part of an expression causing problems.

This change makes it more useful for users of cPython ... but it messes up the analysis currently done by friendly which relies on a single "bad token" begin flagged.

I need to use this information to do the same kind of highlighting that cPython does. Additionally, I need to figure out how to use this information in a way that is compatible with the analysis I was doing before.

This is discussed in https://github.com/python/cpython/pull/25582/files, but has not made it to the What's New section yet.

aroberge commented 3 years ago

Just thinking about how to go about this ... Perhaps what I can do is check if these attributes exist. If they do not exist, I can artificially add them, something like:

e.end_lineno = e.lineno (or None)
e.end_offset = e.offst + 1

This would likely make the analysis going forward much easier when new Python versions are introduced.

aroberge commented 3 years ago

This has been taken care of in previous commits.