Where is the error?

dn PythonList at DancesWithMice.info
Sun Aug 6 20:18:23 EDT 2023


On 07/08/2023 08.41, Peter J. Holzer via Python-list wrote:
> Mostly, error messages got a lot better in Python 3.10, but this one had
> me scratching my head for a few minutes.
...

> 
> The error message is now a lot better, of course, but the fact that it
> points at the expression *before* the error completely threw me. The
> underlined expression is clearly not missing a comma, nor is there an
> error before that. My real program was a bit longer of course, so I
> checked the lines before that to see if I forgot to close any
> parentheses. Took me some time to notice the missing comma *after* the
> underlined expression.
> 
> Is this "clairvoyant" behaviour a side-effect of the new parser or was
> that a deliberate decision?

Found myself chuckling at this - not to be unkind, but because can 
easily imagine such confusion on my own part.

The issue of unhelpful error messages or information aimed at a similar 
but different context, has been the story of our lives. Advice to 
trainees has always been to cast-about looking for the error - rather 
than taking the line-number as a precise location. Have made a note to 
avoid advising folk to work 'backwards'!

Meantime (back at the ranch?), haven't experienced this. Using an IDE 
means all such stuff is reported, as one types, through highlights and 
squiggly lines (which should(?) be considered and cleared - before 
pressing the GO-button).

In this case, the PyCharm* editor adds red-squiggles where the commas 
should have been. Hovering the cursor over a squiggle, the IDE reports 
"',' expected"! Its PythonConsole behaves similarly (without offering a 
'hover'). Plus, even after the closing brace, it continues to assume a 
multi-line compound-statement (and thus won't execute, per expected REPL 
behavior).


Way-back (grey-beard time!) when we submitted card-decks of code to be 
compiled over-night, one idea to avoid expensive, trivial errors/eras; 
was that spelling-checkers should be built-in to compilers, eg to 
auto-magically correct typos, eg

	AFF 1 TO TOTAL

instead of:

	ADD 1 TO TOTAL

These days, we can look at code from two or more years ago, 'produced' 
by ChatGPT (et al), aka "The Stochastic Parrot". There is some thought 
that artificial 'intelligence' will one-day be able to do the coding for 
us/predict what is required/act as a crystal ball...

Speaking of which, and just because I could, here's what Chat-GPT had to 
say when I asked "what's wrong with ...":

«The issue in the given Python code is that you're missing commas 
between the key-value pairs in the dictionary. Commas are required to 
separate different key-value pairs within a dictionary. Here's the 
corrected version of the code:
...
»

Question: If a Chat-AI is built into the IDE (I stripped such out from 
mine), does it take-over error reporting and diagnosis (and offer the 
option of replacing with its 'corrected version'?) - rather than 
requiring an extra copy-paste step, per above?
(and need for my assumption of where the error is located)


Hope you've exerted copyright over the "clairvoyant" description!


* JetBrains kindly sponsor our PUG with a monthly door-prize.
-- 
-- 
Regards,
=dn


More information about the Python-list mailing list