futzing with alignment

This commit is contained in:
Paul R. Tagliamonte 2013-04-09 20:44:05 -04:00
parent b71d5c597e
commit c0b34181bc

View File

@ -83,8 +83,7 @@ def builds(_type):
def _raise_wrong_args_number(expression, error): def _raise_wrong_args_number(expression, error):
err = TypeError(error % (expression.pop(0), err = TypeError(error % (expression.pop(0), len(expression)))
len(expression)))
err.start_line = expression.start_line err.start_line = expression.start_line
err.start_column = expression.start_column err.start_column = expression.start_column
raise err raise err
@ -94,18 +93,15 @@ def checkargs(exact=None, min=None, max=None):
def _dec(fn): def _dec(fn):
def checker(self, expression): def checker(self, expression):
if exact is not None and (len(expression) - 1) != exact: if exact is not None and (len(expression) - 1) != exact:
_raise_wrong_args_number(expression, _raise_wrong_args_number(
"`%%s' needs %d arguments, got %%d" % expression, "`%%s' needs %d arguments, got %%d" % exact)
exact)
if min is not None and (len(expression) - 1) < min: if min is not None and (len(expression) - 1) < min:
_raise_wrong_args_number( _raise_wrong_args_number(expression,
expression,
"`%%s' needs at least %d arguments, got %%d" % (min)) "`%%s' needs at least %d arguments, got %%d" % (min))
if max is not None and (len(expression) - 1) > max: if max is not None and (len(expression) - 1) > max:
_raise_wrong_args_number( _raise_wrong_args_number(expression,
expression,
"`%%s' needs at most %d arguments, got %%d" % (max)) "`%%s' needs at most %d arguments, got %%d" % (max))
return fn(self, expression) return fn(self, expression)
@ -140,8 +136,7 @@ class HyASTCompiler(object):
def _mangle_branch(self, tree, start_line, start_column): def _mangle_branch(self, tree, start_line, start_column):
# If tree is empty, just return a pass statement # If tree is empty, just return a pass statement
if tree == []: if tree == []:
return [ast.Pass(lineno=start_line, return [ast.Pass(lineno=start_line, col_offset=start_column)]
col_offset=start_column)]
ret = [] ret = []
tree = list(flatten_literal_list(tree)) tree = list(flatten_literal_list(tree))
@ -157,7 +152,7 @@ class HyASTCompiler(object):
if isinstance(el, ast.FunctionDef): if isinstance(el, ast.FunctionDef):
ret.append(ast.Return( ret.append(ast.Return(
value=ast.Name( value=ast.Name(
arg=el.name, id=el.name, ctx=ast.Load(), arg=el.name,id=el.name, ctx=ast.Load(),
lineno=el.lineno, col_offset=el.col_offset), lineno=el.lineno, col_offset=el.col_offset),
lineno=el.lineno, col_offset=el.col_offset)) lineno=el.lineno, col_offset=el.col_offset))
@ -166,9 +161,10 @@ class HyASTCompiler(object):
ret.append(el) ret.append(el)
continue continue
ret.append(ast.Expr(value=el, ret.append(ast.Expr(
lineno=el.lineno, value=el,
col_offset=el.col_offset)) lineno=el.lineno,
col_offset=el.col_offset))
ret.reverse() ret.reverse()
return ret return ret