Posts: 4,655
Threads: 1,498
Joined: Sep 2016
technically, it's correct, but useless:
Output:
lt2a/forums /home/forums 5> cat foo.py
a=1
b=2
c=3
d=f'hello {world{}}'
lt2a/forums /home/forums 6> python3.6 foo.py
File "<fstring>", line 1
(world{})
^
SyntaxError: invalid syntax
lt2a/forums /home/forums 7>
in a big script with lots of similar messages, you won't know which line the error in the f-string is at. did they get this fixed in 3.6.9 or 3.7 or 3.8?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,655
Threads: 1,498
Joined: Sep 2016
Nov-21-2019, 07:15 PM
(This post was last modified: Nov-21-2019, 07:27 PM by Skaperen.)
(Nov-20-2019, 09:03 AM)perfringo Wrote: I can quite clearly see that this is 'line 1' 
But on more serious note - what should be desired behaviour?
desired behavior should be something that (also) indicates the name of the file and line number the f'string is on. it could do this in much the same way it shows where a function was called from or where a module was imported from. the guts of a f-string seem to be compiled like code. i don't know how that gets put together but it is obvious that the f-string gets constructed into a regular string at the point where the f-string appeared in the source code (as executed). hypothetically, an f-string could even appear inside an f-string (i've never tried this, but maybe i should). there should be a stack of data items showing where the code is invoked, which in the case of f-strings would also show where they are. that stack should (also) be shown at that point in the traceback dump. if that information is not recorded, then it should be.
within an f-string there are zero or more clauses within {} that should be enumerated so that which an error exists in (whether detected at compile time or at run time) can be revealed as part of the error traceback. in the case of an f-string inside an f-string (i don't know, yet, if this is allowed), this could be a stack of enumerations identifying the nesting of f-strings (making it even easier to find which expression has the error).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.