Issue - Make except statment lists work with just one item
Without this patch "except (OSError):" leads to an AttributeError.
This patch handles this specific example where test_list is an instance of Name.
@@ -31,6 +31,8 @@ class ExceptionReplacer(Operator):
atom = node.children[1]
test_list = atom.children[1]
+ if isinstance(test_list, Name):
+ return (test_list,)
return test_list.children[::2]
@classmethod
@@ -40,6 +42,10 @@ class ExceptionReplacer(Operator):
"try: raise OSError\nexcept OSError: pass",
"try: raise OSError\nexcept {}: pass".format(CosmicRayTestingException.__name__),
),
+ Example(
+ "try: raise OSError\nexcept (OSError): pass",
+ "try: raise OSError\nexcept ({}): pass".format(CosmicRayTestingException.__name__),
+ ),
Example(
"try: raise OSError\nexcept (OSError, ValueError): pass",
"try: raise OSError\nexcept (OSError, {}): pass".format(CosmicRayTestingException.__name__),
