This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Better token-related error messages
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: skip.montanaro Nosy List: jhylton, skip.montanaro
Priority: normal Keywords: patch

Created on 2002-07-25 16:21 by skip.montanaro, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
token.diff skip.montanaro, 2002-07-25 16:21
token.diff skip.montanaro, 2002-08-04 21:39
Messages (7)
msg40641 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-07-25 16:21
There were some complaints recently on c.l.py about the rather 
non-informative error messages emitted as a result of the tokenizer 
detecting a problem.  In many situations it simply returns 
E_TOKEN which generates a fairly benign, but often unhelpful 
"invalid token" message.

This patch adds several new E_* macrosto Includes/errorcode.h, 
returns them from the appropriate places in Parser/tokenizer.c and 
generates more specific messages in Python/pythonrun.c.  I think the 
error messages are always better, though in some situations they may 
still not be strictly correct.

Assigning to Jeremy since he's the compiler wiz.

Skip
msg40642 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-08-02 17:54
Logged In: YES 
user_id=31392

Is the warning about i vs. j for complex numbers really 
necessary?  It seems like it adds extra, well, complexity 
for a tiny corner case.
msg40643 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-08-02 18:05
Logged In: YES 
user_id=44345

re: i vs. j

Perhaps it's not needed.  The patch was originally designed to address 
the case of runaway triple-quoted strings.  Someone on c.l.py ranted 
about that.  While I was in there, I recalled someone else (perhaps more 
than one person) had berated Python in the past because imaginary 
numbers use 'j' instead of 'i' and decided to stick it in.  It's no big deal to 
take it out.

(When you think about it, they are all corner cases, since most of the 
time the code is syntactically correct. ;-)

S
msg40644 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-08-02 18:17
Logged In: YES 
user_id=31392

The current error message for the complex case seems clear
enough since it identifies exactly the offending character.

>>> 3i+2
  File "<stdin>", line 1
    3i+2
     ^
SyntaxError: invalid syntax

The error message for runaway triple quoted strings is much
more puzzling, since the line of context doesn't have
anything useful on it.

I guess we should think about the others, too:

E_EOLS is marginal, since you do get the line with the error
in the exception.

E_EOFC is a win for the same reason that E_EOFS is, although
I expect it's a less common case.

E_EXP and E_SLASH are borderline -- again because the
current syntax error identifies exactly the line and
character that are causing the problem.

We should get a third opinion, but I'd probably settle for
just E_EOFC and E_EOFS.
msg40645 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-08-04 21:39
Logged In: YES 
user_id=44345

here's a new patch - deletes all but the EOFC & EOFS macros and adds a
test_eof.py test module
msg40646 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-08-14 15:03
Logged In: YES 
user_id=31392

Looks good to me!  Sorry I took so long to review it again.
msg40647 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-08-15 01:25
Logged In: YES 
user_id=44345

implemented in
    Python/pythonrun.c 2.166
    Parser/tokenizer.c 2.64
    Include/errcode.h 2.16
History
Date User Action Args
2022-04-10 16:05:31adminsetgithub: 36926
2002-07-25 16:21:33skip.montanarocreate