diff --git a/src/transformers/hf_argparser.py b/src/transformers/hf_argparser.py index 196035a4d1..045bf79805 100644 --- a/src/transformers/hf_argparser.py +++ b/src/transformers/hf_argparser.py @@ -14,6 +14,7 @@ import dataclasses import json +import os import sys import types from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError @@ -376,7 +377,9 @@ class HfArgumentParser(ArgumentParser): raise ValueError(f"Some keys are not used by the HfArgumentParser: {sorted(unused_keys)}") return tuple(outputs) - def parse_json_file(self, json_file: Union[str, Path], allow_extra_keys: bool = False) -> Tuple[DataClass, ...]: + def parse_json_file( + self, json_file: Union[str, os.PathLike], allow_extra_keys: bool = False + ) -> Tuple[DataClass, ...]: """ Alternative helper method that does not use `argparse` at all, instead loading a json file and populating the dataclass types. @@ -398,7 +401,9 @@ class HfArgumentParser(ArgumentParser): outputs = self.parse_dict(data, allow_extra_keys=allow_extra_keys) return tuple(outputs) - def parse_yaml_file(self, yaml_file: Union[str, Path], allow_extra_keys: bool = False) -> Tuple[DataClass, ...]: + def parse_yaml_file( + self, yaml_file: Union[str, os.PathLike], allow_extra_keys: bool = False + ) -> Tuple[DataClass, ...]: """ Alternative helper method that does not use `argparse` at all, instead loading a yaml file and populating the dataclass types. diff --git a/tests/utils/test_hf_argparser.py b/tests/utils/test_hf_argparser.py index c0fa748cbf..91b0c199ee 100644 --- a/tests/utils/test_hf_argparser.py +++ b/tests/utils/test_hf_argparser.py @@ -379,7 +379,7 @@ class HfArgumentParserTest(unittest.TestCase): os.mkdir(temp_local_path) with open(temp_local_path + ".json", "w+") as f: json.dump(args_dict_for_json, f) - parsed_args = parser.parse_yaml_file(Path(temp_local_path + ".json"))[0] + parsed_args = parser.parse_json_file(Path(temp_local_path + ".json"))[0] args = BasicExample(**args_dict_for_json) self.assertEqual(parsed_args, args)