Fixes for 3.2 - qualname and exception suppressing.
Python 3.2 doesn't have __qualname__ nor does it have exception chain suppressing, so make sure tb walking doesn't crash, and fallback to __name__ when __qualname__ is missing.
This commit is contained in:
parent
cae3cb83fb
commit
87b74c133b
|
@ -128,7 +128,7 @@ def _iter_chain(exc, custom_tb=None, seen=None):
|
|||
its.append(_iter_chain(cause, False, seen))
|
||||
its.append([(_cause_message, None)])
|
||||
elif (context is not None and
|
||||
not exc.__suppress_context__ and
|
||||
not getattr(exc, '__suppress_context__', None) and
|
||||
context not in seen):
|
||||
its.append(_iter_chain(context, None, seen))
|
||||
its.append([(_context_message, None)])
|
||||
|
|
|
@ -13,7 +13,7 @@ try:
|
|||
except ImportError:
|
||||
# support raise_from on 3.x:
|
||||
# submitted to six: https://bitbucket.org/gutworth/six/issue/102/raise-foo-from-bar-is-a-syntax-error-on-27
|
||||
if sys.version_info[:2] > (3, 2):
|
||||
if sys.version_info[:2] > (3, 1):
|
||||
six.exec_("""def raise_from(value, from_value):
|
||||
raise value from from_value
|
||||
""")
|
||||
|
@ -110,6 +110,8 @@ class SyntaxTracebackCases(unittest.TestCase):
|
|||
self.assertEqual(lst, ['KeyboardInterrupt\n'])
|
||||
|
||||
def test_format_exception_only_bad__str__(self):
|
||||
def qualname(X):
|
||||
return getattr(X, '__qualname__', X.__name__)
|
||||
class X(Exception):
|
||||
def __str__(self):
|
||||
1/0
|
||||
|
@ -117,9 +119,9 @@ class SyntaxTracebackCases(unittest.TestCase):
|
|||
self.assertEqual(len(err), 1)
|
||||
str_value = '<unprintable %s object>' % X.__name__
|
||||
if X.__module__ in ('__main__', 'builtins'):
|
||||
str_name = X.__qualname__
|
||||
str_name = qualname(X)
|
||||
else:
|
||||
str_name = '.'.join([X.__module__, X.__qualname__])
|
||||
str_name = '.'.join([X.__module__, qualname(X)])
|
||||
self.assertEqual(err[0], "%s: %s\n" % (str_name, str_value))
|
||||
|
||||
def test_without_exception(self):
|
||||
|
@ -345,6 +347,7 @@ class BaseExceptionReportingTests:
|
|||
self.check_zero_div(blocks[0])
|
||||
self.assertIn('inner_raise() # Marker', blocks[2])
|
||||
|
||||
@unittest.skipIf(sys.version_info[:2] < (3, 3), "Only applies to 3.3+")
|
||||
def test_context_suppression(self):
|
||||
try:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue