@@ -212,8 +212,7 @@ def add_decorator_imports(function_to_optimize, code_context):
212212        file_paths [elem .file_path ].append (elem .qualified_name )
213213    for  file_path ,fns_present  in  file_paths .items ():
214214        #open file 
215-         with  open (file_path , "r" , encoding = "utf-8" ) as  file :
216-             file_contents  =  file .read ()
215+         file_contents  =  file_path .read_text ("utf-8" )
217216        # parse to cst 
218217        module_node  =  cst .parse_module (file_contents )
219218        for  fn_name  in  fns_present :
@@ -229,9 +228,7 @@ def add_decorator_imports(function_to_optimize, code_context):
229228        with  open (file_path , "w" , encoding = "utf-8" ) as  file :
230229            file .write (modified_code )
231230    #Adding profile.enable line for changing the savepath of the data, do this only for the main file and not the helper files 
232-     with  open (function_to_optimize .file_path ,'r' ) as  f :
233-         file_contents  =  f .read ()
231+     file_contents  =  function_to_optimize .file_path .read_text ("utf-8" )
234232    modified_code  =  add_profile_enable (file_contents ,str (line_profile_output_file ))
235-     with  open (function_to_optimize .file_path ,'w' ) as  f :
236-         f .write (modified_code )
233+     function_to_optimize .file_path .write_text (modified_code ,"utf-8" )
237234    return  line_profile_output_file 
0 commit comments