Skip to content

Commit

Permalink
Fix hf_argparser.parse_json_file to open file with utf-8 encoding, cl…
Browse files Browse the repository at this point in the history
…ose file when finished (huggingface#23194)

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

* black formatted
  • Loading branch information
RobertBaruch authored and novice03 committed Jun 23, 2023
1 parent 7251f16 commit c8a5b6b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transformers/hf_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ def parse_json_file(self, json_file: str, allow_extra_keys: bool = False) -> Tup
- 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)

Expand Down

0 comments on commit c8a5b6b

Please sign in to comment.