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
标题: Line numbers reported by extract_stack are offset by the #-*- encoding line
类型: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
状态: closed Resolution: duplicate
Dependencies: 后续: [Py3k] line number is wrong after encoding declaration
View: 2384
分配给: 抄送列表: ddvoinikov, pitrou, vstinner
优先级: normal 关键字:

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) 日期: 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) 日期: 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
历史
日期 用户 动作 参数
2022-04-11 14:56:34admin修改github: 47081
2008-09-27 15:32:44benjamin.peterson修改状态: open -> closed
resolution: duplicate
后续: [Py3k] line number is wrong after encoding declaration
2008-09-27 15:21:55vstinner修改抄送: + vstinner
消息: + msg73927
2008-07-24 15:26:33pitrou修改抄送: + pitrou
2008-05-12 04:52:03ddvoinikov创建