Op 6/06/2023 om 16:48 schreef Chris Angelico via Python-list:
On Wed, 7 Jun 2023 at 00:42, Roel Schroeven <r...@roelschroeven.net> wrote:
> (Recently there has been an effort to provide clearer and more useful
> error messages; this seems to be a case where there is still room for
> improvement: "SyntaxError: invalid syntax" doesn't immediately remind me
> of that fact that 'return' is a keyword and therefor can't be used as an
> attribute.)

That's true, but depending on exactly how you're seeing the error, it
might highlight the exact part that's a problem:

>>> opt.return
   File "<stdin>", line 1
     opt.return
         ^^^^^^
SyntaxError: invalid syntax

It's extremely hard to guess what the programmer might have intended
in these situations, as the error might not be the word "return" but
perhaps the punctuation (maybe that was supposed to be a semicolon, or
something). So Python does the best it can, and points out that the
"return" keyword in this context doesn't make syntactic sense.
Ah yes, good point.

--
"Don't Panic."
        -- Douglas Adams, The Hitchhiker's Guide to the Galaxy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to