Fix hf_argparser.parse_json_file to open file with utf-8 encoding, close file when finished (#23194)

* Open json args in utf-8 encoding, close file when finished

* black formatted
This commit is contained in:
Robert Baruch 2023-05-07 16:06:24 -07:00 committed by GitHub
parent 6f8a02844a
commit dbc12269ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -401,8 +401,8 @@ class HfArgumentParser(ArgumentParser):
- the dataclass instances in the same order as they were passed to the initializer.
"""
open_json_file = open(Path(json_file))
data = json.loads(open_json_file.read())
with open(Path(json_file), encoding="utf-8") as open_json_file:
data = json.loads(open_json_file.read())
outputs = self.parse_dict(data, allow_extra_keys=allow_extra_keys)
return tuple(outputs)