1
- """ Using ast transformer to fix some issues with automatic pydantic generation"""
1
+ """ Using ast transformer to fix issues with automatic pydantic generation"""
2
2
3
- import sys
4
3
import ast
4
+ import sys
5
+
5
6
import astor
6
7
7
8
@@ -20,7 +21,7 @@ def visit_Expr(self, node):
20
21
if isinstance (node .value , ast .Call ):
21
22
# Check if the call expression is an attribute (method call)
22
23
if isinstance (node .value .func , ast .Attribute ):
23
- # Check if the method call matches the specified class and method name
24
+ # Check if the method call matches the specified class
24
25
if (
25
26
isinstance (node .value .func .value , ast .Name )
26
27
and node .value .func .value .id == self .class_name
@@ -79,7 +80,9 @@ def edit_pydantic(input_file, output_file):
79
80
transformer_class = ClassRemover (class_name = "LangString" )
80
81
tree_modclass = transformer_class .visit (tree )
81
82
82
- transformer_tp = TypeReplacer (old_type = "LangString" , new_type = "Dict[str, str]" )
83
+ transformer_tp = TypeReplacer (
84
+ old_type = "LangString" , new_type = "Dict[str, str]"
85
+ )
83
86
tree_modclass_modtype = transformer_tp .visit (tree_modclass )
84
87
85
88
with open (output_file , "w" ) as file :
@@ -93,6 +96,7 @@ def edit_pydantic(input_file, output_file):
93
96
else :
94
97
output_file = sys .argv [2 ]
95
98
print (
96
- f"Fixing automatically generated pydantic file { input_file } and saving to { output_file } "
99
+ f"Fixing automatically generated pydantic file { input_file } "
100
+ f"and saving to { output_file } "
97
101
)
98
102
edit_pydantic (input_file , output_file )
0 commit comments