Commit 46b99911 authored by Petr Viktorin's avatar Petr Viktorin

2to3: Apply the 'except' fixer

parent 0927accf
lib2to3.fixes.fix_basestring
lib2to3.fixes.fix_dict
lib2to3.fixes.fix_except
lib2to3.fixes.fix_exec
lib2to3.fixes.fix_execfile
lib2to3.fixes.fix_funcattrs
......
......@@ -978,7 +978,7 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None, raise_on_f
result = compile([pyx_file], options)
if result.num_errors > 0:
any_failures = 1
except (EnvironmentError, PyrexError), e:
except (EnvironmentError, PyrexError) as e:
sys.stderr.write('%s\n' % e)
any_failures = 1
# XXX
......
......@@ -70,7 +70,7 @@ class EmbedSignature(CythonTransform):
except Exception:
try:
return self._fmt_expr_node(default_val)
except AttributeError, e:
except AttributeError as e:
return '<???>'
def _fmt_arg(self, arg):
......
......@@ -169,7 +169,7 @@ def parse_command_line(args):
options.compiler_directives = Options.parse_directive_list(
x_args, relaxed_bool=True,
current_settings=options.compiler_directives)
except ValueError, e:
except ValueError as e:
sys.stderr.write("Error in compiler directive: %s\n" % e.args[0])
sys.exit(1)
elif option.startswith('--debug'):
......
......@@ -128,7 +128,7 @@ class UtilityCodeBase(object):
del tags['substitute']
try:
code = Template(code).substitute(vars(Naming))
except (KeyError, ValueError), e:
except (KeyError, ValueError) as e:
raise RuntimeError("Error parsing templated utility code of type '%s' at line %d: %s" % (
type, begin_lineno, e))
......
......@@ -2943,7 +2943,7 @@ class IndexNode(ExprNode):
index = self.index.compile_time_value(denv)
try:
return base[index]
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def is_ephemeral(self):
......@@ -4023,7 +4023,7 @@ class SliceIndexNode(ExprNode):
stop = self.stop.compile_time_value(denv)
try:
return base[start:stop]
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def analyse_target_declaration(self, env):
......@@ -4423,7 +4423,7 @@ class SliceNode(ExprNode):
step = self.step.compile_time_value(denv)
try:
return slice(start, stop, step)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def may_be_none(self):
......@@ -4585,7 +4585,7 @@ class SimpleCallNode(CallNode):
args = [arg.compile_time_value(denv) for arg in self.args]
try:
return function(*args)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def analyse_as_type(self, env):
......@@ -5324,7 +5324,7 @@ class GeneralCallNode(CallNode):
keyword_args = self.keyword_args.compile_time_value(denv)
try:
return function(*positional_args, **keyword_args)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def explicit_args_kwds(self):
......@@ -5545,7 +5545,7 @@ class AsTupleNode(ExprNode):
arg = self.arg.compile_time_value(denv)
try:
return tuple(arg)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def analyse_types(self, env):
......@@ -5615,7 +5615,7 @@ class MergedDictNode(ExprNode):
if reject_duplicates and key in result:
raise ValueError("duplicate keyword argument found: %s" % key)
result[key] = value
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
return result
......@@ -5797,7 +5797,7 @@ class AttributeNode(ExprNode):
obj = self.obj.compile_time_value(denv)
try:
return getattr(obj, attr)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def type_dependencies(self, env):
......@@ -6923,7 +6923,7 @@ class TupleNode(SequenceNode):
values = self.compile_time_value_list(denv)
try:
return tuple(values)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def generate_operation_code(self, code):
......@@ -7571,7 +7571,7 @@ class SetNode(ExprNode):
values = [arg.compile_time_value(denv) for arg in self.args]
try:
return set(values)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def generate_evaluation_code(self, code):
......@@ -7622,7 +7622,7 @@ class DictNode(ExprNode):
for item in self.key_value_pairs]
try:
return dict(pairs)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def type_dependencies(self, env):
......@@ -8960,7 +8960,7 @@ class UnopNode(ExprNode):
operand = self.operand.compile_time_value(denv)
try:
return func(operand)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def infer_type(self, env):
......@@ -9057,7 +9057,7 @@ class NotNode(UnopNode):
operand = self.operand.compile_time_value(denv)
try:
return not operand
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def infer_unop_type(self, env, operand_type):
......@@ -9824,7 +9824,7 @@ class BinopNode(ExprNode):
operand2 = self.operand2.compile_time_value(denv)
try:
return func(operand1, operand2)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def infer_type(self, env):
......@@ -10249,7 +10249,7 @@ class DivNode(NumBinopNode):
func = self.find_compile_time_binary_operator(
operand1, operand2)
return func(operand1, operand2)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
def _check_truedivision(self, env):
......@@ -10924,7 +10924,7 @@ class CmpNode(object):
operand2 = self.operand2.compile_time_value(denv)
try:
result = func(operand1, operand2)
except Exception, e:
except Exception as e:
self.compile_time_value_error(e)
result = None
if result:
......
......@@ -354,7 +354,7 @@ class Context(object):
raise RuntimeError(
"Formal grammer can only be used with compiled Cython with an available pgen.")
ConcreteSyntaxTree.p_module(source_filename)
except UnicodeDecodeError, e:
except UnicodeDecodeError as e:
#import traceback
#traceback.print_exc()
raise self._report_decode_error(source_desc, e)
......@@ -699,7 +699,7 @@ def main(command_line = 0):
result = compile(sources, options)
if result.num_errors > 0:
any_failures = 1
except (EnvironmentError, PyrexError), e:
except (EnvironmentError, PyrexError) as e:
sys.stderr.write(str(e) + '\n')
any_failures = 1
if any_failures:
......
......@@ -397,7 +397,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if target_file_dir != target_dir and not os.path.exists(target_file_dir):
try:
os.makedirs(target_file_dir)
except OSError, e:
except OSError as e:
import errno
if e.errno != errno.EEXIST:
raise
......
......@@ -1037,7 +1037,7 @@ class MemoryViewSliceTypeNode(CBaseTypeNode):
try:
axes_specs = MemoryView.get_axes_specs(env, self.axes)
except CompileError, e:
except CompileError as e:
error(e.position, e.message_only)
self.type = PyrexTypes.ErrorType()
return self.type
......@@ -7657,7 +7657,7 @@ class ParallelStatNode(StatNode, ParallelNode):
try:
self.kwargs = self.kwargs.compile_time_value(env)
except Exception, e:
except Exception as e:
error(self.kwargs.pos, "Only compile-time values may be "
"supplied as keyword arguments")
else:
......
......@@ -255,7 +255,7 @@ class PostParse(ScopeTrackingTransform):
newdecls.append(decl)
node.declarators = newdecls
return stats
except PostParseError, e:
except PostParseError as e:
# An error in a cdef clause is ok, simply remove the declaration
# and try to move on to report more errors
self.context.nonfatal_error(e)
......
......@@ -3329,7 +3329,7 @@ def p_compiler_directive_comments(s):
try:
result.update(Options.parse_directive_list(
directives, ignore_unknown=True))
except ValueError, e:
except ValueError as e:
s.error(e.args[0], fatal=False)
s.next()
return result
......
......@@ -327,15 +327,15 @@ def run_pipeline(pipeline, source, printtree=True):
data = phase(data)
if DebugFlags.debug_verbose_pipeline:
print " %.3f seconds" % (time() - t)
except CompileError, err:
except CompileError as err:
# err is set
Errors.report_error(err)
error = err
except InternalError, err:
except InternalError as err:
# Only raise if there was not an earlier error
if Errors.num_errors == 0:
raise
error = err
except AbortError, err:
except AbortError as err:
error = err
return (error, data)
......@@ -490,7 +490,7 @@ class Scope(object):
try:
type = PyrexTypes.create_typedef_type(name, base_type, cname,
(visibility == 'extern'))
except ValueError, e:
except ValueError as e:
error(pos, e.args[0])
type = PyrexTypes.error_type
entry = self.declare_type(name, type, pos, cname,
......
......@@ -176,7 +176,7 @@ class TreeVisitor(object):
raise
except Errors.AbortError:
raise
except Exception, e:
except Exception as e:
if DebugFlags.debug_no_exception_intercept:
raise
self._raise_compiler_error(obj, e)
......
......@@ -61,7 +61,7 @@ class CythonDebugWriter(object):
try:
os.makedirs(self.output_dir)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
......
......@@ -36,7 +36,7 @@ def print_on_call_decorator(func):
try:
return func(self, *args, **kwargs)
except Exception, e:
except Exception as e:
_debug("An exception occurred:", traceback.format_exc(e))
raise
......
......@@ -180,7 +180,7 @@ class Lexicon(object):
re.build_machine(machine, initial_state, final_state,
match_bol=1, nocase=0)
final_state.set_action(action, priority=-token_number)
except Errors.PlexError, e:
except Errors.PlexError as e:
raise e.__class__("Token number %d: %s" % (token_number, e))
def parse_token_definition(self, token_spec):
......
......@@ -298,7 +298,7 @@ class Template(object):
try:
try:
value = eval(code, self.default_namespace, ns)
except SyntaxError, e:
except SyntaxError as e:
raise SyntaxError(
'invalid syntax in expression: %s' % code)
return value
......@@ -354,7 +354,7 @@ class Template(object):
'(no default_encoding provided)' % value)
try:
value = value.decode(self.default_encoding)
except UnicodeDecodeError, e:
except UnicodeDecodeError as e:
raise UnicodeDecodeError(
e.encoding,
e.object,
......
......@@ -101,7 +101,7 @@ class CythonTest(unittest.TestCase):
try:
func()
self.fail("Expected an exception of type %r" % exc_type)
except exc_type, e:
except exc_type as e:
self.assert_(isinstance(e, exc_type))
return e
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment