f-string syntax deficiency?

Roel Schroeven roel at roelschroeven.net
Tue Jun 6 10:56:35 EDT 2023


Op 6/06/2023 om 16:48 schreef Chris Angelico via Python-list:
> On Wed, 7 Jun 2023 at 00:42, Roel Schroeven <roel at 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



More information about the Python-list mailing list