From 09fc080ed1df48baf9c85c862a4f7f80dfdba902 Mon Sep 17 00:00:00 2001 From: newturok Date: Sun, 24 Sep 2023 03:01:15 +0300 Subject: [PATCH] Refactor code to use dictionary comprehension In this commit, we have refactored the code to improve its readability and conciseness by replacing the traditional `for` loop with a dictionary comprehension. The original code iterated through `nodes.NODE_CLASS_MAPPINGS`, calling the `node_info` function for each element and populating the `out` dictionary. The refactored code achieves the same functionality but in a more Pythonic way. This refactoring not only makes the code more concise but also improves its maintainability and reduces the potential for errors. It adheres to Python's best practices for clean and efficient code, enhancing the overall quality of the codebase. --- server.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index b2e16716b..54bdba725 100644 --- a/server.py +++ b/server.py @@ -411,10 +411,8 @@ class PromptServer(): @routes.get("/object_info") async def get_object_info(request): - out = {} - for x in nodes.NODE_CLASS_MAPPINGS: - out[x] = node_info(x) - return web.json_response(out) + node_info_dict = {node_name: node_info(node_name) for node_name in nodes.NODE_CLASS_MAPPINGS} + return web.json_response(node_info_dict) @routes.get("/object_info/{node_class}") async def get_object_info_node(request):