Skip to content

Commit

Permalink
running new pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
djarecka committed Jun 18, 2024
1 parent d14fb10 commit ccba7f9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions scripts/fix_pydantic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
""" Using ast transformer to fix some issues with automatic pydantic generation"""
""" Using ast transformer to fix issues with automatic pydantic generation"""

import sys
import ast
import sys

import astor


Expand All @@ -20,7 +21,7 @@ def visit_Expr(self, node):
if isinstance(node.value, ast.Call):
# Check if the call expression is an attribute (method call)
if isinstance(node.value.func, ast.Attribute):
# Check if the method call matches the specified class and method name
# Check if the method call matches the specified class
if (
isinstance(node.value.func.value, ast.Name)
and node.value.func.value.id == self.class_name
Expand Down Expand Up @@ -79,7 +80,9 @@ def edit_pydantic(input_file, output_file):
transformer_class = ClassRemover(class_name="LangString")
tree_modclass = transformer_class.visit(tree)

transformer_tp = TypeReplacer(old_type="LangString", new_type="Dict[str, str]")
transformer_tp = TypeReplacer(
old_type="LangString", new_type="Dict[str, str]"
)
tree_modclass_modtype = transformer_tp.visit(tree_modclass)

with open(output_file, "w") as file:
Expand All @@ -93,6 +96,7 @@ def edit_pydantic(input_file, output_file):
else:
output_file = sys.argv[2]
print(
f"Fixing automatically generated pydantic file {input_file} and saving to {output_file}"
f"Fixing automatically generated pydantic file {input_file} "
f"and saving to {output_file}"
)
edit_pydantic(input_file, output_file)

0 comments on commit ccba7f9

Please sign in to comment.