This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Line numbers reported by extract_stack are offset by the #-*- encoding line
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: duplicate
Dependencies: Superseder: [Py3k] line number is wrong after encoding declaration
View: 2384
Assigned To: Nosy List: ddvoinikov, pitrou, vstinner
Priority: normal Keywords:

Created on 2008-05-12 04:52 by ddvoinikov, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg66708 - (view) Author: Dmitry Dvoinikov (ddvoinikov) Date: 2008-05-12 04:51
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'
msg73927 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-09-27 15:21
This bug is a duplicate of the issue 2384: I tried your example with 
the patch tokenizer-coding-2.patch and your bug is fixed:
 * first example (no coding): this is line 3
 * second example (with coding): this is line 4
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47081
2008-09-27 15:32:44benjamin.petersonsetstatus: open -> closed
resolution: duplicate
superseder: [Py3k] line number is wrong after encoding declaration
2008-09-27 15:21:55vstinnersetnosy: + vstinner
messages: + msg73927
2008-07-24 15:26:33pitrousetnosy: + pitrou
2008-05-12 04:52:03ddvoinikovcreate