@@ -85,8 +85,8 @@ def _check_files_formatting(
85
85
failed_files = set ()
86
86
for file_path in files :
87
87
try :
88
- with open (file_path , "r" ) as fh :
89
- code = fh .read ()
88
+ with open (file_path , "r" , encoding = "utf-8" ) as handle :
89
+ code = handle .read ()
90
90
success , actually_formatted , formatted_code = _format_code (
91
91
code , line_length , file_path , safety_checks
92
92
)
@@ -108,9 +108,9 @@ def _check_files_formatting(
108
108
formattable_files .add (file_path )
109
109
elif not success :
110
110
failed_files .add (file_path )
111
- except OSError as e :
111
+ except OSError as exceptions :
112
112
print (
113
- "Cannot open file '{}': {}" .format (file_path , e .strerror ),
113
+ "Cannot open file '{}': {}" .format (file_path , exceptions .strerror ),
114
114
file = sys .stderr ,
115
115
)
116
116
failed_files .add (file_path )
@@ -140,22 +140,22 @@ def _format_files(files: List[str], line_length: int, safety_checks: bool) -> No
140
140
failed_files = set ()
141
141
for file_path in files :
142
142
try :
143
- with open (file_path , "r+" ) as fh :
144
- code = fh .read ()
143
+ with open (file_path , "r+" , encoding = "utf-8" ) as handle :
144
+ code = handle .read ()
145
145
success , actually_formatted , formatted_code = _format_code (
146
146
code , line_length , file_path , safety_checks
147
147
)
148
148
if success and actually_formatted :
149
149
print ("reformatted {}" .format (file_path ))
150
150
formatted_files .add (file_path )
151
- fh .seek (0 )
152
- fh .truncate (0 )
153
- fh .write (formatted_code )
151
+ handle .seek (0 )
152
+ handle .truncate (0 )
153
+ handle .write (formatted_code )
154
154
elif not success :
155
155
failed_files .add (file_path )
156
- except OSError as e :
156
+ except OSError as exceptions :
157
157
print (
158
- "Cannot open file '{}': {}" .format (file_path , e .strerror ),
158
+ "Cannot open file '{}': {}" .format (file_path , exceptions .strerror ),
159
159
file = sys .stderr ,
160
160
)
161
161
failed_files .add (file_path )
@@ -198,19 +198,19 @@ def _format_code(
198
198
given_code_parse_tree = code_parse_tree ,
199
199
given_code_comment_parse_tree = comment_parse_tree ,
200
200
)
201
- except lark .exceptions .UnexpectedToken as e :
201
+ except lark .exceptions .UnexpectedToken as exception :
202
202
success = False
203
203
print (
204
204
f"{ file_path } :\n " ,
205
- lark_unexpected_token_to_str (e , code ),
205
+ lark_unexpected_token_to_str (exception , code ),
206
206
sep = "\n " ,
207
207
file = sys .stderr ,
208
208
)
209
- except lark .exceptions .UnexpectedInput as e :
209
+ except lark .exceptions .UnexpectedInput as exception :
210
210
success = False
211
211
print (
212
212
f"{ file_path } :\n " ,
213
- lark_unexpected_input_to_str (e ),
213
+ lark_unexpected_input_to_str (exception ),
214
214
sep = "\n " ,
215
215
file = sys .stderr ,
216
216
)
0 commit comments