Issue 2832: Line numbers reported by extract_stack are offset by the #-*- encoding line (original) (raw)

Stack trace information extracted with traceback.extract_stack is incorrect in that the #-*- line causes double counting. For example:

#comment from traceback import extract_stack print("this is line", extract_stack()[-1][1])

prints 'this is line 3', but

#comment #-- coding: windows-1251 -- from traceback import extract_stack print("this is line", extract_stack()[-1][1])

prints 'this is line 6'