On Tue, 30 Dec 2025 at 01:57, Peter J. Holzer <[email protected]> wrote:
>
> On 2025-12-29 22:50:41 +1100, Chris Angelico via Python-list wrote:
> > On Mon, 29 Dec 2025 at 22:47, Peter J. Holzer <[email protected]> wrote:
> > > As for the error message, I agree that "SyntaxError: invalid syntax" is
> > > a pretty uninformative message. Python error messages in general have
> > > become very good over the last few years, so that feels like a bit of a
> > > throwback. I think it would be generally useful to improve that message
> > > (maybe something like "expected identfier, got reserved word 'class'").
> >
> > I wouldn't call it a throwback.
>
> Yes, that was perhaps too strong a word. Anachronism? No, that's the
> wrong direction.
>
> Point is that we've been spoiled with high quality error messages in the
> last few years, so now it's jarring to read a message which would have
> been perfectly normal less than 10 years ago.

Yep. That is exactly the definition of "spoiled", we come to expect
this level of helpfulness everywhere :)

> > Every improvement to the error messages happened because someone wrote
> > code to detect a specific category of error and give a more helpful
> > message.
>
> Of course. Python doesn't improve itself. There are always people doing
> the work. And useful error messages are particularly tricky.

Indeed. But when it's something that seems fairly clear (eg
"identifier, dot, keyword"), it shouldn't be too hard to craft a check
for it.

One useful trick that's done in a lot of the recent error message
updates is having the main work only done when the error gets printed.
You'll see suggestions like this:

>>> math.log()
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    math.log()
    ^^^^
NameError: name 'math' is not defined. Did you forget to import 'math'?

but if you catch the exception, it's not so helpful:

>>> try: math.log()
... except NameError as e: print(repr(e))
...
NameError("name 'math' is not defined")

This way, the price isn't paid every time a NameError is raised, but
only when it reaches the default exception handler. A useful way to
improve interactive helpfulness while minimizing the impact on
runtime.

ChrisA
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to