Minor cleanup in hy.compiler: try, except
This commit is contained in:
parent
50aa930232
commit
0d2749d5cd
@ -769,13 +769,8 @@ class HyASTCompiler(object):
|
|||||||
def compile_try_expression(self, expr):
|
def compile_try_expression(self, expr):
|
||||||
expr.pop(0) # try
|
expr.pop(0) # try
|
||||||
|
|
||||||
try:
|
|
||||||
body = expr.pop(0)
|
|
||||||
except IndexError:
|
|
||||||
body = []
|
|
||||||
|
|
||||||
# (try something…)
|
# (try something…)
|
||||||
body = self.compile(body)
|
body = self.compile(expr.pop(0) if expr else [])
|
||||||
|
|
||||||
var = self.get_anon_var()
|
var = self.get_anon_var()
|
||||||
name = ast.Name(id=ast_str(var), arg=ast_str(var),
|
name = ast.Name(id=ast_str(var), arg=ast_str(var),
|
||||||
@ -797,9 +792,6 @@ class HyASTCompiler(object):
|
|||||||
col_offset=expr.start_column)
|
col_offset=expr.start_column)
|
||||||
|
|
||||||
body = body.stmts
|
body = body.stmts
|
||||||
if not body:
|
|
||||||
body = [ast.Pass(lineno=expr.start_line,
|
|
||||||
col_offset=expr.start_column)]
|
|
||||||
|
|
||||||
orelse = []
|
orelse = []
|
||||||
finalbody = []
|
finalbody = []
|
||||||
@ -895,10 +887,7 @@ class HyASTCompiler(object):
|
|||||||
def _compile_catch_expression(self, expr, var):
|
def _compile_catch_expression(self, expr, var):
|
||||||
catch = expr.pop(0) # catch
|
catch = expr.pop(0) # catch
|
||||||
|
|
||||||
try:
|
exceptions = expr.pop(0) if expr else HyList()
|
||||||
exceptions = expr.pop(0)
|
|
||||||
except IndexError:
|
|
||||||
exceptions = HyList()
|
|
||||||
|
|
||||||
# exceptions catch should be either:
|
# exceptions catch should be either:
|
||||||
# [[list of exceptions]]
|
# [[list of exceptions]]
|
||||||
@ -920,6 +909,7 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
# [variable [list of exceptions]]
|
# [variable [list of exceptions]]
|
||||||
# let's pop variable and use it as name
|
# let's pop variable and use it as name
|
||||||
|
name = None
|
||||||
if len(exceptions) == 2:
|
if len(exceptions) == 2:
|
||||||
name = exceptions.pop(0)
|
name = exceptions.pop(0)
|
||||||
if not isinstance(name, HySymbol):
|
if not isinstance(name, HySymbol):
|
||||||
@ -937,13 +927,8 @@ class HyASTCompiler(object):
|
|||||||
else:
|
else:
|
||||||
# Python2 requires an ast.Name, set to ctx Store.
|
# Python2 requires an ast.Name, set to ctx Store.
|
||||||
name = self._storeize(name, self.compile(name))
|
name = self._storeize(name, self.compile(name))
|
||||||
else:
|
|
||||||
name = None
|
|
||||||
|
|
||||||
try:
|
exceptions_list = exceptions.pop(0) if exceptions else []
|
||||||
exceptions_list = exceptions.pop(0)
|
|
||||||
except IndexError:
|
|
||||||
exceptions_list = []
|
|
||||||
|
|
||||||
if isinstance(exceptions_list, list):
|
if isinstance(exceptions_list, list):
|
||||||
if len(exceptions_list):
|
if len(exceptions_list):
|
||||||
|
Loading…
Reference in New Issue
Block a user