diff --git a/hcl2/builder.py b/hcl2/builder.py index 7381a669..1ba9f7b0 100644 --- a/hcl2/builder.py +++ b/hcl2/builder.py @@ -19,7 +19,7 @@ def __init__(self, attributes: Optional[dict] = None): self.attributes = attributes or {} def block( - self, block_type: str, labels: Optional[List[str]] = None, **attributes: dict + self, block_type: str, labels: Optional[List[str]] = None, **attributes ) -> "Builder": """Create a block within this HCL document.""" labels = labels or [] diff --git a/hcl2/reconstructor.py b/hcl2/reconstructor.py index 04880453..4f401855 100644 --- a/hcl2/reconstructor.py +++ b/hcl2/reconstructor.py @@ -5,9 +5,9 @@ from typing import List, Dict, Callable, Optional, Union, Any, Tuple from lark import Lark, Tree -from lark.grammar import Terminal, NonTerminal, Symbol +from lark.grammar import Terminal, Symbol from lark.lexer import Token, PatternStr, TerminalDef -from lark.reconstruct import Reconstructor, is_iter_empty +from lark.reconstruct import Reconstructor from lark.tree_matcher import is_discarded_terminal from lark.visitors import Transformer_InPlace @@ -94,15 +94,12 @@ def __default__(self, data, children, meta): to_write += item else: if isinstance(item, Token): - assert Terminal(item.type) == sym, item # annotate the leaf with the specific rule (data) and # terminal (sym) it was generated from to_write.append((data, sym, item)) else: - assert NonTerminal(item.data) == sym, (sym, item) to_write.append(item) - assert is_iter_empty(iter_args) return to_write diff --git a/test/unit/test_builder.py b/test/unit/test_builder.py index 0ab3792a..53294828 100644 --- a/test/unit/test_builder.py +++ b/test/unit/test_builder.py @@ -1,6 +1,7 @@ +# pylint:disable=C0116 + """Test building an HCL file from scratch""" -import json from pathlib import Path from unittest import TestCase @@ -51,21 +52,24 @@ def test_locals_embdedded_condition_tf(self): def test_locals_embedded_function_tf(self): builder = hcl2.Builder() - builder.block( - "locals", - function_test='${var.basename}-${var.forwarder_function_name}_${md5("${var.vpc_id}${data.aws_region.current.name}")}', + function_test = ( + "${var.basename}-${var.forwarder_function_name}_" + '${md5("${var.vpc_id}${data.aws_region.current.name}")}' ) + builder.block("locals", function_test=function_test) self.compare_filenames(builder, "locals_embedded_function.tf") def test_locals_embedded_interpolation_tf(self): builder = hcl2.Builder() - builder.block( - "locals", - embedded_interpolation='${module.special_constants.aws_accounts["aaa-${local.foo}-${local.bar}"]}/us-west-2/key_foo', + embedded_interpolation = ( + "${module.special_constants.aws_accounts" + '["aaa-${local.foo}-${local.bar}"]}/us-west-2/key_foo' ) + builder.block("locals", embedded_interpolation=embedded_interpolation) + self.compare_filenames(builder, "locals_embedded_interpolation.tf") def test_provider_function_tf(self):