Conversation
68eb7b6 to
886f3fb
Compare
hailangvn
left a comment
There was a problem hiding this comment.
Thank you for the work. Please check my comments. Thanks.
| """ | ||
| Convert `states` to XML attributes (readonly, required, invisible). | ||
| """ | ||
| logger.info(f"Parsing states: {states}") # 添加日志,打印解析到的 states |
There was a problem hiding this comment.
Please translate the comment to English.
| field_name = target.id | ||
| states_value = None | ||
| for keyword in getattr(node.value, "keywords", []): | ||
| if keyword.arg == "states": |
There was a problem hiding this comment.
I think it is better to skip below logic if it is not states.
| if keyword.arg == "states": | |
| if keyword.arg != "states": | |
| continue |
| if isinstance(keyword.value, ast.Dict): | ||
| # Direct dictionary | ||
| states_value = ast.literal_eval(keyword.value) | ||
| elif isinstance(keyword.value, ast.Name): | ||
| # Variable reference | ||
| var_name = keyword.value.id | ||
| if var_name in variable_definitions: | ||
| states_value = ast.literal_eval( | ||
| variable_definitions[var_name] | ||
| ) |
There was a problem hiding this comment.
| if isinstance(keyword.value, ast.Dict): | |
| # Direct dictionary | |
| states_value = ast.literal_eval(keyword.value) | |
| elif isinstance(keyword.value, ast.Name): | |
| # Variable reference | |
| var_name = keyword.value.id | |
| if var_name in variable_definitions: | |
| states_value = ast.literal_eval( | |
| variable_definitions[var_name] | |
| ) | |
| if isinstance(keyword.value, ast.Dict): | |
| # Direct dictionary | |
| states_value = ast.literal_eval(keyword.value) | |
| elif isinstance(keyword.value, ast.Name): | |
| # Variable reference | |
| var_name = keyword.value.id | |
| if var_name in variable_definitions: | |
| states_value = ast.literal_eval( | |
| variable_definitions[var_name] | |
| ) |
| if not xml_attrs: | ||
| logger.info( | ||
| f"No valid attributes generated from states: {states}" | ||
| ) # 添加日志,打印未生成有效属性的情况 |
There was a problem hiding this comment.
Please translate the comment to English.
|
|
||
| # Write the updated XML back to the file | ||
| with open(xml_file, "wb") as f: | ||
| tree.write(f, pretty_print=True, encoding="utf-8", xml_declaration=True) |
There was a problem hiding this comment.
This line causes test failure because lxml.etree is hard coded to write header with single quote. It is better to only write when there is change.
| tree.write(f, pretty_print=True, encoding="utf-8", xml_declaration=True) | |
| tree.write(f, pretty_print=True, encoding="utf-8", | |
| doctype='<?xml version="1.0" encoding="utf-8"?>') |
| if current_model: | ||
| model_field_mapping[current_model] = {} |
There was a problem hiding this comment.
These two lines are not needed as model_field_mapping[current_model] is not used anywhere and current_model is part of the key used in model_field_mapping.
| # Create a copy of arch_root to modify independently | ||
| arch_root_copy = et.Element(arch_root.tag, arch_root.attrib) | ||
| for child in arch_root: | ||
| arch_root_copy.append(child) |
There was a problem hiding this comment.
I could not see the benefit of arch_root_copy. Below code prove that it moves, not copies, children from arch_root to arch_root_copy.
| # Create a copy of arch_root to modify independently | |
| arch_root_copy = et.Element(arch_root.tag, arch_root.attrib) | |
| for child in arch_root: | |
| arch_root_copy.append(child) | |
| # Create a copy of arch_root to modify independently | |
| arch_root_copy = et.Element(arch_root.tag, arch_root.attrib) | |
| for child in arch_root: | |
| arch_root_copy.append(child) | |
| logger.info( | |
| f"arch_root_copy, {arch_root_copy}, {len(arch_root_copy)}" | |
| ) | |
| logger.info(f"arch_root, {arch_root}, {len(arch_root)}") |
No description provided.