Python Forum
traceback reports "wrong" file and line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
traceback reports "wrong" file and line
#1
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.
Reply
#2
I can quite clearly see that this is 'line 1' Smile

But on more serious note - what should be desired behaviour?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(Nov-20-2019, 09:03 AM)perfringo Wrote: I can quite clearly see that this is 'line 1' Smile

But on more serious note - what should be desired behaviour?

Would be the exact line number. In this case, line #4
Reply
#4
(Nov-20-2019, 09:03 AM)perfringo Wrote: I can quite clearly see that this is 'line 1' Smile

But on more serious note - what should be desired behaviour?
Hi! In your case particularly you'll have the number of the line (4). Good luck!
Reply
#5
First of all - I didn't pay enough attention. So - Mea culpa

So far I have managed to get SyntaxErrors caused by f-strings with correct line and file numbers. However, this particular instance indeed behaves unexpectedly.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#6
(Nov-20-2019, 09:03 AM)perfringo Wrote: I can quite clearly see that this is 'line 1' Smile

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb traceback and multi-line statement Skaperen 0 834 Jan-31-2023, 12:23 AM
Last Post: Skaperen
  a program i want: file line slicing Skaperen 4 3,189 Dec-19-2018, 01:47 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020