From 047956c59b8b842ae9bcfa86d5c82418106ef9ba Mon Sep 17 00:00:00 2001 From: James King Date: Fri, 19 Apr 2013 10:34:17 -0400 Subject: [PATCH] Clean up based on review --- bin/hy2py | 3 +-- hy/compiler.py | 7 ++----- hy/util.py | 40 ------------------------------------- tests/compilers/test_ast.py | 1 - 4 files changed, 3 insertions(+), 48 deletions(-) diff --git a/bin/hy2py b/bin/hy2py index 9598999..20d6cf0 100755 --- a/bin/hy2py +++ b/bin/hy2py @@ -3,7 +3,6 @@ from __future__ import print_function from hy.importer import (import_file_to_ast, import_file_to_module, import_file_to_hst) -from hy.util import dump #import astor.codegen import sys @@ -17,7 +16,7 @@ print("") _ast = import_file_to_ast(sys.argv[1]) print("") print("") -print(dump(_ast)) +print(ast.dump(_ast)) print("") print("") #print(astor.codegen.to_source(_ast)) diff --git a/hy/compiler.py b/hy/compiler.py index 507abe8..324eaed 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -190,15 +190,13 @@ class HyASTCompiler(object): def _parse_lambda_list(self, exprs): """ Return FunctionDef parameter values from lambda list.""" - exprs.reverse() args = [] defaults = [] varargs = None kwargs = None lambda_keyword = None - while exprs: - expr = exprs.pop() + for expr in exprs: if isinstance(expr, HyLambdaListKeyword): if expr not in expr._valid_types: @@ -236,9 +234,8 @@ class HyASTCompiler(object): "one &key argument") # As you can see, Python has a funny way of # defining keyword arguments. - for k in expr.keys(): + for k, v in expr.items(): args.append(k) - for v in expr.values(): defaults.append(self.compile(v)) elif lambda_keyword == "&optional": # not implemented yet. diff --git a/hy/util.py b/hy/util.py index f506adf..a600b5e 100644 --- a/hy/util.py +++ b/hy/util.py @@ -18,7 +18,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -import ast import sys @@ -35,42 +34,3 @@ def flatten_literal_list(entry): yield x # needs more yield-from else: yield e - - -def dump(node, annotate_fields=True, include_attributes=False, indent=' '): - """ - Return a formatted dump of the tree in *node*. This is mainly useful for - debugging purposes. The returned string will show the names and the values - for fields. This makes the code impossible to evaluate, so if evaluation is - wanted *annotate_fields* must be set to False. Attributes such as line - numbers and column offsets are not dumped by default. If this is wanted, - *include_attributes* can be set to True. - - Original author: Alex Leone (acleone ~AT~ gmail.com), 2010-01-30 - """ - def _format(node, level=0): - if isinstance(node, ast.AST): - fields = [(a, _format(b, level)) for a, b in ast.iter_fields(node)] - if include_attributes and node._attributes: - fields.extend([(a, _format(getattr(node, a), level)) - for a in node._attributes]) - return ''.join([ - node.__class__.__name__, - '(', - ', '.join(('%s=%s' % field for field in fields) - if annotate_fields else - (b for a, b in fields)), - ')']) - elif isinstance(node, list): - lines = ['['] - lines.extend((indent * (level + 2) + _format(x, level + 2) + ',' - for x in node)) - if len(lines) > 1: - lines.append(indent * (level + 1) + ']') - else: - lines[-1] += ']' - return '\n'.join(lines) - return repr(node) - if not isinstance(node, ast.AST): - raise TypeError('expected AST, got %r' % node.__class__.__name__) - return _format(node) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index c6decf9..dc6daac 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -24,7 +24,6 @@ from __future__ import unicode_literals from hy import HyString from hy.compiler import hy_compile, HyCompileError from hy.lex import tokenize -from hy.util import dump import ast import sys