Refactor code_parser.py and test_custom_component.py

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-14 10:00:43 -03:00
commit 7ec8a6c2a8
2 changed files with 16 additions and 15 deletions

View file

@ -6,8 +6,8 @@ from typing import Any, Dict, List, Type, Union
from cachetools import TTLCache, cachedmethod, keys
from fastapi import HTTPException
from langflow.interface.custom.schema import CallableCodeDetails, ClassCodeDetails
from langflow.interface.custom.schema import (CallableCodeDetails,
ClassCodeDetails)
class CodeSyntaxError(HTTPException):
@ -57,7 +57,7 @@ class CodeParser:
ast.Assign: self.parse_global_vars,
}
def __get_tree(self):
def get_tree(self):
"""
Parses the provided code to validate its syntax.
It tries to parse the code into an abstract syntax tree (AST).
@ -313,7 +313,7 @@ class CodeParser:
"""
Runs all parsing operations and returns the resulting data.
"""
tree = self.__get_tree()
tree = self.get_tree()
for node in ast.walk(tree):
self.parse_node(node)