Fixes for 3.3.

Handle frame.clear being absent (and accept it won't be cleared in < 3.4).
Don't try to check coding: behaviour which was fixed in 3.4.
This commit is contained in:
Robert Collins 2014-11-21 10:19:02 +13:00
parent f187c1fbb0
commit cae3cb83fb
2 changed files with 8 additions and 4 deletions

View File

@ -305,11 +305,12 @@ def extract_stack(f=None, limit=None):
stack.reverse()
return stack
_identity = lambda:None
def clear_frames(tb):
"Clear all references to local variables in the frames of a traceback."
while tb is not None:
try:
tb.tb_frame.clear()
getattr(tb.tb_frame, 'clear', _identity)()
except RuntimeError:
# Ignore the exception raised if the frame is still executing.
pass

View File

@ -191,7 +191,9 @@ class SyntaxTracebackCases(unittest.TestCase):
do_test(" \t\f\n# coding: {0}\n".format(charset),
text, charset, 5)
# Issue #18960: coding spec should has no effect
do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
# (Fixed in 3.4)
if sys.version_info[:2] > (3, 3):
do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
class TracebackFormatTests(unittest.TestCase):
@ -457,5 +459,6 @@ class MiscTracebackCases(unittest.TestCase):
# Clear traceback frames
traceback.clear_frames(tb)
# Local variable dict should now be empty.
self.assertEqual(len(inner_frame.f_locals), 0)
# Local variable dict should now be empty (on Python 3.4+)
if sys.version_info[:2] > (3, 3):
self.assertEqual({}, inner_frame.f_locals)