Small code simplification
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
5bed886362
commit
5a6e3ca31b
@ -169,7 +169,9 @@ class Result(object):
|
||||
|
||||
If there is no expression context, we return a "None" expression.
|
||||
"""
|
||||
if not self.expr:
|
||||
if self.expr:
|
||||
return self.expr
|
||||
|
||||
# Spoof the position of the last statement for our generated None
|
||||
lineno = 0
|
||||
col_offset = 0
|
||||
@ -184,8 +186,6 @@ class Result(object):
|
||||
col_offset=col_offset)
|
||||
# XXX: Likely raise Exception here - this will assertionfail
|
||||
# pypy since the ast will be out of numerical order.
|
||||
else:
|
||||
return self.expr
|
||||
|
||||
def expr_as_stmt(self):
|
||||
"""Convert the Result's expression context to a statement
|
||||
@ -257,20 +257,6 @@ class Result(object):
|
||||
)
|
||||
|
||||
|
||||
def _collect(results):
|
||||
"""Collect the expression contexts from a list of results
|
||||
|
||||
This returns a list of the expression contexts, and the sum of the Result
|
||||
objects passed as arguments.
|
||||
"""
|
||||
compiled_exprs = []
|
||||
ret = Result()
|
||||
for result in results:
|
||||
ret += result
|
||||
compiled_exprs.append(ret.force_expr)
|
||||
return compiled_exprs, ret
|
||||
|
||||
|
||||
def _branch(results):
|
||||
"""Make a branch out of a list of Result objects
|
||||
|
||||
@ -363,8 +349,6 @@ class HyASTCompiler(object):
|
||||
if not isinstance(ret, Result):
|
||||
ret = Result() + ret
|
||||
return ret
|
||||
else:
|
||||
return None
|
||||
|
||||
def compile(self, tree):
|
||||
try:
|
||||
@ -384,7 +368,18 @@ class HyASTCompiler(object):
|
||||
raise HyCompileError(Exception("Unknown type: `%s'" % _type))
|
||||
|
||||
def _compile_collect(self, exprs):
|
||||
return _collect(self.compile(expr) for expr in exprs)
|
||||
"""Collect the expression contexts from a list of compiled expression.
|
||||
|
||||
This returns a list of the expression contexts, and the sum of the
|
||||
Result objects passed as arguments.
|
||||
|
||||
"""
|
||||
compiled_exprs = []
|
||||
ret = Result()
|
||||
for expr in exprs:
|
||||
ret += self.compile(expr)
|
||||
compiled_exprs.append(ret.force_expr)
|
||||
return compiled_exprs, ret
|
||||
|
||||
def _compile_branch(self, exprs):
|
||||
return _branch(self.compile(expr) for expr in exprs)
|
||||
|
Loading…
Reference in New Issue
Block a user