From ba3e7701eb4e44506fe1a14d62b2df8756af443f Mon Sep 17 00:00:00 2001 From: idealbuq <iryna.dealbuquerquesilva@cea.fr> Date: Fri, 27 Sep 2024 13:52:49 +0000 Subject: [PATCH] Corrected typehints in show_graphview.py --- aidge_core/show_graphview.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/aidge_core/show_graphview.py b/aidge_core/show_graphview.py index 34a77f7cf..f63586439 100644 --- a/aidge_core/show_graphview.py +++ b/aidge_core/show_graphview.py @@ -4,18 +4,18 @@ import builtins import aidge_core import numpy as np -def dfs(graph, node, visited_nodes, sorted_nodes) -> None: +def dfs(graph : aidge_core.GraphView, node : aidge_core.Node, visited_nodes : list[aidge_core.Node], sorted_nodes : list[aidge_core.Node]) -> None: """ Performs the depth-first search algorithm for topological sorting. - :param graph: An unsorted GraphView of Aidge + :param graph: An unsorted GraphView of Aidge. :type graph: aidge_core.GraphView - :param node: The GraphView's Node that is being treated + :param node: The GraphView's Node that is being treated. :type node: aidge_core.Node :param visited_nodes: List of nodes that have already been visited. - :type visited_nodes: list + :type visited_nodes: list[aidge_core.Node] :param sorted_nodes: List of nodes that have already been sorted. - :type sorted_nodes: list + :type sorted_nodes: list[aidge_core.Node] """ node_children = node.get_children() @@ -44,14 +44,14 @@ def dfs(graph, node, visited_nodes, sorted_nodes) -> None: return None -def topological_sort(graph : aidge_core.GraphView) -> list: +def topological_sort(graph : aidge_core.GraphView) -> list[aidge_core.Node]: """ Performs topological sorting by applying depth-first search algorithm recursively. - :param graph: An unsorted GraphView of Aidge + :param graph: An unsorted GraphView of Aidge. :type graph: aidge_core.GraphView :return: A list with the GraphView's sorted nodes. - :rtype: list + :rtype: list[aidge_core.Node] """ input_nodes = graph.get_input_nodes() @@ -66,14 +66,14 @@ def topological_sort(graph : aidge_core.GraphView) -> list: return sorted_nodes -def retrieve_operator_attrs(node : aidge_core.Node) -> dict: +def retrieve_operator_attrs(node : aidge_core.Node) -> dict[str, int, float, bool, None]: """ Returns the dictionary containing the attributes of a given Node. :param graph: A Node in the list of sorted nodes. :type graph: aidge_core.Node :return: A dictionary with the Node's attributes. - :rtype: dict + :rtype: dict[str, int, float, bool, None] """ if node.get_operator().attr is not None: node_attr_dict = node.get_operator().attr.dict() @@ -86,7 +86,7 @@ def retrieve_operator_attrs(node : aidge_core.Node) -> dict: return node_attr_dict -def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_trainable_params_embed : bool, params_file_format : str, path_trainable_params : str) -> dict: +def create_dict(sorted_nodes : list[aidge_core.Node], write_trainable_params_ext : bool, write_trainable_params_embed : bool, params_file_format : str, path_trainable_params : str) -> dict[str, int, float, bool, None]: """ Creates a dictionary to store the information of a given sorted GraphView. @@ -102,7 +102,7 @@ def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_tr :type path_trainable_params: str :return: A dictionary with the GraphView description. - :rtype: dict + :rtype: dict[str, int, float, bool, None] """ graphview_dict = {'graph': []} @@ -215,14 +215,14 @@ def create_dict(sorted_nodes : list, write_trainable_params_ext : bool, write_tr return graphview_dict -def write_dict_json(graphview_dict : dict, json_path : str) -> None: +def write_dict_json(graphview_dict : dict[str, int, float, bool, None], json_path : str) -> None: """ Writes dictionary containing GraphView description to a JSON file. :param graphview_dict: A dictionary with the GraphView description. - :type graphview_dict: dict + :type graphview_dict: dict[str, int, float, bool, None] :param json_path: Path to write JSON file. - :type json_path: str. + :type json_path: str """ with open(json_path, 'w') as fp: @@ -234,10 +234,10 @@ def gview_to_json(gview : aidge_core.GraphView, json_path : str, write_trainable """ Generates the description for a GraphView in the JSON format. - :param graph: A GraphView of Aidge + :param graph: A GraphView of Aidge. :type graph: aidge_core.GraphView :param json_path: Path to write JSON file. - :type json_path: str. + :type json_path: str :param write_trainable_params_ext: Whether or not to write the eventual trainable parameters of the Nodes in an external file. :type write_trainable_params_ext: bool :param write_trainable_params_embed: Whether or not to write the eventual trainable parameters of the Nodes in the same file as the dict (embed). -- GitLab