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.
This commit is contained in:
newturok 2023-09-24 03:01:15 +03:00 committed by GitHub
parent 76cdc809bf
commit 09fc080ed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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):