# Buggy code
def _visit_string(self, node):
    string = node.value.s
    if string.startswith("@nni."):
        self.annotated = True
    else:
        return node  # not an annotation, ignore it

    if string.startswith("@nni.get_next_parameter"):
        deprecated_message = "'@nni.get_next_parameter' is deprecated in annotation due to inconvenience. Please remove this line in the trial code."
        print_warning(deprecated_message)
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="Get next parameter here...")],
                keywords=[],
            )
        )

    if string.startswith("@nni.report_intermediate_result"):
        module = ast.parse(string[1:])
        arg = module.body[0].value.args[0]
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="nni.report_intermediate_result: "), arg],
                keywords=[],
            )
        )

    if string.startswith("@nni.report_final_result"):
        module = ast.parse(string[1:])
        arg = module.body[0].value.args[0]
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="nni.report_final_result: "), arg],
                keywords=[],
            )
        )

    if string.startswith("@nni.mutable_layers"):
        return parse_annotation_mutable_layers(string[1:], node.lineno)

    if string.startswith("@nni.variable") or string.startswith("@nni.function_choice"):
        self.stack[-1] = string[1:]  # mark that the next expression is annotated
        return None

    raise AssertionError("Unexpected annotation function")


# Traceback (AssertionError)
Traceback (most recent call last):
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 355, in parse
transformer.visit(ast_tree)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 278, in visit
return self._visit_children(node)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 333, in _visit_children
self.generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 295, in visit
return self._visit_children(node)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 333, in _visit_children
self.generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 295, in visit
return self._visit_children(node)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 333, in _visit_children
self.generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 295, in visit
return self._visit_children(node)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 333, in _visit_children
self.generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 286, in visit
return self._visit_string(node)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 328, in _visit_string
raise AssertionError('Unexpected annotation function')
AssertionError: Unexpected annotation function

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/__init__.py", line 145, in _generate_specific_file
annotated_code = specific_code_generator.parse(src.read(), para_cfg["parameters"], module)
File "/data/hdd3/yugzh/ENAS_NLP/venv/lib/python3.5/site-packages/nni_annotation/specific_code_generator.py", line 357, in parse
raise RuntimeError('%d: %s' % (ast_tree.last_line, exc.args[0]))
AttributeError: 'Module' object has no attribute 'last_line'

# Fixed code
def _visit_string(self, node):
    string = node.value.s
    if string.startswith("@nni."):
        self.annotated = True
    else:
        return node  # not an annotation, ignore it

    if string.startswith("@nni.get_next_parameter"):
        deprecated_message = (
            "'@nni.get_next_parameter' is deprecated in annotation due to inconvenience. "
            "Please remove this line in the trial code."
        )
        print_warning(deprecated_message)
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="Get next parameter here...")],
                keywords=[],
            )
        )

    if string.startswith("@nni.training_update"):
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="Training update here...")],
                keywords=[],
            )
        )

    if string.startswith("@nni.report_intermediate_result"):
        module = ast.parse(string[1:])
        arg = module.body[0].value.args[0]
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="nni.report_intermediate_result: "), arg],
                keywords=[],
            )
        )

    if string.startswith("@nni.report_final_result"):
        module = ast.parse(string[1:])
        arg = module.body[0].value.args[0]
        return ast.Expr(
            value=ast.Call(
                func=ast.Name(id="print", ctx=ast.Load()),
                args=[ast.Str(s="nni.report_final_result: "), arg],
                keywords=[],
            )
        )

    if string.startswith("@nni.mutable_layers"):
        return parse_annotation_mutable_layers(string[1:], node.lineno)

    if string.startswith("@nni.variable") or string.startswith("@nni.function_choice"):
        self.stack[-1] = string[1:]  # mark that the next expression is annotated
        return None

    raise AssertionError("Unexpected annotation function")