Skip to content

Commit 6913d01

Browse files
author
Pietro Albini
committed
Fix wrong traceback in deprecation warnings on Python 3.5.0
Python 3.5.0 has a bug in the `traceback.extract_stack` method, which returns an extra internal stack frame. This causes some trouble in the nice deprecation warnings message, because the hint about where to change things points to a different file (and line number). This commit adds a special workaround activated only on Python 3.5.0. Upstream issue: http://bugs.python.org/issue25108
1 parent 5168cfb commit 6913d01

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

botogram/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def get(k):
7373

7474
def warn(stack_pos, before_message, after_message=None):
7575
"""Issue a warning caused by user code"""
76+
# This is a workaround for http://bugs.python.org/issue25108
77+
# In Python 3.5.0, traceback.extract_stack returns an additional internal
78+
# stack frame, which causes a lot of trouble around there.
79+
if sys.version_info[:3] == (3, 5, 0):
80+
stack_pos -= 1
81+
7682
frame = traceback.extract_stack()[stack_pos-1]
7783
at_message = "At: %s (line %s)" % (frame[0], frame[1])
7884

0 commit comments

Comments
 (0)