Skip to content
Snippets Groups Projects
Commit 202cadd8 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

clearer

parent 51777ad1
No related branches found
Tags v2.14_b2
No related merge requests found
......@@ -45,24 +45,18 @@ class rethrow_as(object):
Should return a text
"""
# You can also provide just two exceptions
two_entries_provided = True
if len(pairs) != 2:
two_entries_provided = False
else:
a, b = pairs
if isinstance(b, (tuple, list)):
two_entries_provided = False
elif not ((b is None) or (issubclass(b, BaseException))):
two_entries_provided = False
if two_entries_provided:
self.mapping = [(a, b)]
else:
self.mapping = list(pairs)
try:
a, b = pairs # throws ValueError
op = issubclass(b, BaseException) # throws TypeError
except TypeError:
op = b is None
except ValueError:
op = False
if op:
pairs = [pairs]
self.mapping = list(pairs)
self.exception_preprocessor = kwargs.get('exception_preprocessor', repr)
def __call__(self, fun):
......
......@@ -56,7 +56,7 @@ class TestStuff(unittest.TestCase):
def test_issue_14a(self):
@rethrow_as(((NameError, ValueError), TypeError))
@rethrow_as(*(((NameError, ValueError), TypeError), ))
def ro(p):
raise p()
......@@ -66,7 +66,7 @@ class TestStuff(unittest.TestCase):
def test_issue_14b(self):
@rethrow_as((((NameError, ValueError), TypeError), ))
@rethrow_as((NameError, ValueError), TypeError)
def ro(p):
raise p()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment