

'''simple docstring'''
import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
_lowerCamelCase      					=     sys.version_info >= (3, 10)


def  a__       (    _SCREAMING_SNAKE_CASE   :       List[Any]=None	,				_SCREAMING_SNAKE_CASE   :       Any=None				)     ->					int:


	"""simple docstring"""





	return field(default_factory=lambda: default	,				metadata=_SCREAMING_SNAKE_CASE				)
@dataclass
class 					_snake_case		:
			__A  :	int
			__A  :	float
			__A  :	str
			__A  :	bool




@dataclass
class 					_snake_case		:
			__A  :	int        =42
			__A  :	str        =field(default="toto"			,			metadata={"help": "help message"})




@dataclass
class 					_snake_case		:
			__A  :	bool        =False
			__A  :	bool        =True
			__A  :	Optional[bool]        =None




class 					_snake_case		(__SCREAMING_SNAKE_CASE):
			__A  :	Optional[int]        ="titi"
			__A  :	str        ="toto"




class 					_snake_case		(__SCREAMING_SNAKE_CASE):
			__A  :	List[Any]        ="titi"
			__A  :	List[Any]        ="toto"
			__A  :	Optional[Any]        =42




@dataclass
class 					_snake_case		:
			__A  :	BasicEnum        ="toto"






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  BasicEnum(self.foo     )




@dataclass
class 					_snake_case		:
			__A  :	MixedTypeEnum        ="toto"






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  MixedTypeEnum(self.foo     )




@dataclass
class 					_snake_case		:
			__A  :	Optional[int]        =None
			__A  :	Optional[float]        =field(default=__SCREAMING_SNAKE_CASE			,			metadata={"help": "help message"})
			__A  :	Optional[str]        =None
			__A  :	Optional[List[str]]        =list_field(default=[])
			__A  :	Optional[List[int]]        =list_field(default=[])




@dataclass
class 					_snake_case		:
			__A  :	List[int]        =list_field(default=[])
			__A  :	List[int]        =list_field(default=[1, 2, 3])
			__A  :	List[str]        =list_field(default=["Hallo", "Bonjour", "Hello"])
			__A  :	List[float]        =list_field(default=[0.1, 0.2, 0.3])




@dataclass
class 					_snake_case		:
			__A  :	List[int]        =field()
			__A  :	str        =field()
			__A  :	BasicEnum        =field()






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  BasicEnum(self.required_enum     )




@dataclass
class 					_snake_case		:
			__A  :	int
			__A  :	"BasicEnum"        =field()
			__A  :	"Optional[bool]"        =None
			__A  :	"str"        =field(default="toto"			,			metadata={"help": "help message"})
			__A  :	"List[str]"        =list_field(default=["Hallo", "Bonjour", "Hello"])


if is_python_no_less_than_3_10:
					@dataclass
					class 					_snake_case		:
								__A  :	bool        =False
								__A  :	bool        =True
								__A  :	bool | None        =None




					@dataclass
					class 					_snake_case		:
								__A  :	int | None        =None
								__A  :	float | None        =field(default=__SCREAMING_SNAKE_CASE			,			metadata={"help": "help message"})
								__A  :	str | None        =None
								__A  :	list[str] | None        =list_field(default=[])
								__A  :	list[int] | None        =list_field(default=[])





class 					_snake_case		(unittest.TestCase):






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case     ):
				self.assertEqual(len(a._actions     )			,len(b._actions     )     )
				for x, y in zip(a._actions			,b._actions     ):
					UpperCAmelCase_     :      List[str]						=  {k: v for k, v in vars(_snake_case     ).items() if k != "container"}
					UpperCAmelCase_     :      List[Any]						=  {k: v for k, v in vars(_snake_case     ).items() if k != "container"}

					# Choices with mixed type have custom function as "type"
					# So we need to compare results directly for equality
					if xx.get("choices"			,_snake_case     ) and yy.get("choices"			,_snake_case     ):
						for expected_choice in yy["choices"] + xx["choices"]:
							self.assertEqual(xx["type"](_snake_case     )			,yy["type"](_snake_case     )     )
						del xx["type"], yy["type"]

					self.assertEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Optional[Any]						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Dict						=  argparse.ArgumentParser()
				expected.add_argument("--foo"			,type=_snake_case			,required=_snake_case     )
				expected.add_argument("--bar"			,type=_snake_case			,required=_snake_case     )
				expected.add_argument("--baz"			,type=_snake_case			,required=_snake_case     )
				expected.add_argument("--flag"			,type=_snake_case			,default=_snake_case			,const=_snake_case			,nargs="?"     )
				self.argparsersEqual(_snake_case			,_snake_case     )

				UpperCAmelCase_     :      int						=  ["--foo", "1", "--baz", "quux", "--bar", "0.5"]
				((UpperCAmelCase_)					,					)     :      int						=  parser.parse_args_into_dataclasses(_snake_case			,look_for_args_file=_snake_case     )
				self.assertFalse(example.flag     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      str						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Optional[int]						=  argparse.ArgumentParser()
				expected.add_argument("--foo"			,default=42			,type=_snake_case     )
				expected.add_argument("--baz"			,default="toto"			,type=_snake_case			,help="help message"     )
				self.argparsersEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      List[Any]						=  argparse.ArgumentParser()
				expected.add_argument("--foo"			,type=_snake_case			,default=_snake_case			,const=_snake_case			,nargs="?"     )
				expected.add_argument("--baz"			,type=_snake_case			,default=_snake_case			,const=_snake_case			,nargs="?"     )
				# A boolean no_* argument always has to come after its "default: True" regular counter-part
				# and its default must be set to False
				expected.add_argument("--no_baz"			,action="store_false"			,default=_snake_case			,dest="baz"     )
				expected.add_argument("--opt"			,type=_snake_case			,default=_snake_case     )

				UpperCAmelCase_     :      Tuple						=  [WithDefaultBoolExample]
				if is_python_no_less_than_3_10:
					dataclass_types.append(_snake_case     )

				for dataclass_type in dataclass_types:
					UpperCAmelCase_     :      Union[str, Any]						=  HfArgumentParser(_snake_case     )
					self.argparsersEqual(_snake_case			,_snake_case     )

					UpperCAmelCase_     :      Optional[Any]						=  parser.parse_args([]     )
					self.assertEqual(_snake_case			,Namespace(foo=_snake_case			,baz=_snake_case			,opt=_snake_case     )     )

					UpperCAmelCase_     :      List[str]						=  parser.parse_args(["--foo", "--no_baz"]     )
					self.assertEqual(_snake_case			,Namespace(foo=_snake_case			,baz=_snake_case			,opt=_snake_case     )     )

					UpperCAmelCase_     :      Any						=  parser.parse_args(["--foo", "--baz"]     )
					self.assertEqual(_snake_case			,Namespace(foo=_snake_case			,baz=_snake_case			,opt=_snake_case     )     )

					UpperCAmelCase_     :      List[str]						=  parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]     )
					self.assertEqual(_snake_case			,Namespace(foo=_snake_case			,baz=_snake_case			,opt=_snake_case     )     )

					UpperCAmelCase_     :      int						=  parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]     )
					self.assertEqual(_snake_case			,Namespace(foo=_snake_case			,baz=_snake_case			,opt=_snake_case     )     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Union[str, Any]						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Any						=  argparse.ArgumentParser()
				expected.add_argument(
				    "--foo"			,default="toto"			,choices=["titi", "toto", 42]			,type=make_choice_type_function(["titi", "toto", 42]     )			,)
				self.argparsersEqual(_snake_case			,_snake_case     )

				UpperCAmelCase_     :      List[str]						=  parser.parse_args([]     )
				self.assertEqual(args.foo			,"toto"     )
				UpperCAmelCase_     :      Tuple						=  parser.parse_args_into_dataclasses([]     )[0]
				self.assertEqual(enum_ex.foo			,MixedTypeEnum.toto     )

				UpperCAmelCase_     :      Dict						=  parser.parse_args(["--foo", "titi"]     )
				self.assertEqual(args.foo			,"titi"     )
				UpperCAmelCase_     :      Tuple						=  parser.parse_args_into_dataclasses(["--foo", "titi"]     )[0]
				self.assertEqual(enum_ex.foo			,MixedTypeEnum.titi     )

				UpperCAmelCase_     :      int						=  parser.parse_args(["--foo", "42"]     )
				self.assertEqual(args.foo			,42     )
				UpperCAmelCase_     :      Any						=  parser.parse_args_into_dataclasses(["--foo", "42"]     )[0]
				self.assertEqual(enum_ex.foo			,MixedTypeEnum.fourtytwo     )






			def 		UpperCamelCase__							(  self     ):
				@dataclass
				class 					_snake_case		:
							__A  :	Literal["titi", "toto", 42]        ="toto"




				UpperCAmelCase_     :      List[Any]						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Optional[int]						=  argparse.ArgumentParser()
				expected.add_argument(
				    "--foo"			,default="toto"			,choices=("titi", "toto", 42)			,type=make_choice_type_function(["titi", "toto", 42]     )			,)
				self.argparsersEqual(_snake_case			,_snake_case     )

				UpperCAmelCase_     :      Union[str, Any]						=  parser.parse_args([]     )
				self.assertEqual(args.foo			,"toto"     )

				UpperCAmelCase_     :      int						=  parser.parse_args(["--foo", "titi"]     )
				self.assertEqual(args.foo			,"titi"     )

				UpperCAmelCase_     :      int						=  parser.parse_args(["--foo", "42"]     )
				self.assertEqual(args.foo			,42     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Optional[int]						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Optional[Any]						=  argparse.ArgumentParser()
				expected.add_argument("--foo_int"			,nargs="+"			,default=[]			,type=_snake_case     )
				expected.add_argument("--bar_int"			,nargs="+"			,default=[1, 2, 3]			,type=_snake_case     )
				expected.add_argument("--foo_str"			,nargs="+"			,default=["Hallo", "Bonjour", "Hello"]			,type=_snake_case     )
				expected.add_argument("--foo_float"			,nargs="+"			,default=[0.1, 0.2, 0.3]			,type=_snake_case     )

				self.argparsersEqual(_snake_case			,_snake_case     )

				UpperCAmelCase_     :      Any						=  parser.parse_args([]     )
				self.assertEqual(
				    _snake_case			,Namespace(foo_int=[]			,bar_int=[1, 2, 3]			,foo_str=["Hallo", "Bonjour", "Hello"]			,foo_float=[0.1, 0.2, 0.3]     )			,)

				UpperCAmelCase_     :      Tuple						=  parser.parse_args("--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7".split()     )
				self.assertEqual(_snake_case			,Namespace(foo_int=[1]			,bar_int=[2, 3]			,foo_str=["a", "b", "c"]			,foo_float=[0.1, 0.7]     )     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Any						=  argparse.ArgumentParser()
				expected.add_argument("--foo"			,default=_snake_case			,type=_snake_case     )
				expected.add_argument("--bar"			,default=_snake_case			,type=_snake_case			,help="help message"     )
				expected.add_argument("--baz"			,default=_snake_case			,type=_snake_case     )
				expected.add_argument("--ces"			,nargs="+"			,default=[]			,type=_snake_case     )
				expected.add_argument("--des"			,nargs="+"			,default=[]			,type=_snake_case     )

				UpperCAmelCase_     :      Dict						=  [OptionalExample]
				if is_python_no_less_than_3_10:
					dataclass_types.append(_snake_case     )

				for dataclass_type in dataclass_types:
					UpperCAmelCase_     :      Optional[Any]						=  HfArgumentParser(_snake_case     )

					self.argparsersEqual(_snake_case			,_snake_case     )

					UpperCAmelCase_     :      Optional[Any]						=  parser.parse_args([]     )
					self.assertEqual(_snake_case			,Namespace(foo=_snake_case			,bar=_snake_case			,baz=_snake_case			,ces=[]			,des=[]     )     )

					UpperCAmelCase_     :      List[str]						=  parser.parse_args("--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3".split()     )
					self.assertEqual(_snake_case			,Namespace(foo=12			,bar=3.14			,baz="42"			,ces=["a", "b", "c"]			,des=[1, 2, 3]     )     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      List[Any]						=  argparse.ArgumentParser()
				expected.add_argument("--required_list"			,nargs="+"			,type=_snake_case			,required=_snake_case     )
				expected.add_argument("--required_str"			,type=_snake_case			,required=_snake_case     )
				expected.add_argument(
				    "--required_enum"			,type=make_choice_type_function(["titi", "toto"]     )			,choices=["titi", "toto"]			,required=_snake_case			,)
				self.argparsersEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      int						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Tuple						=  argparse.ArgumentParser()
				expected.add_argument("--foo"			,type=_snake_case			,required=_snake_case     )
				expected.add_argument(
				    "--required_enum"			,type=make_choice_type_function(["titi", "toto"]     )			,choices=["titi", "toto"]			,required=_snake_case			,)
				expected.add_argument("--opt"			,type=_snake_case			,default=_snake_case     )
				expected.add_argument("--baz"			,default="toto"			,type=_snake_case			,help="help message"     )
				expected.add_argument("--foo_str"			,nargs="+"			,default=["Hallo", "Bonjour", "Hello"]			,type=_snake_case     )
				self.argparsersEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Optional[int]						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      List[str]						=  {
				    "foo": 12,
				    "bar": 3.14,
				    "baz": "42",
				    "flag": True,
				}

				UpperCAmelCase_     :      Any						=  parser.parse_dict(_snake_case     )[0]
				UpperCAmelCase_     :      Dict						=  BasicExample(**_snake_case     )
				self.assertEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Any						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      str						=  {
				    "foo": 12,
				    "bar": 3.14,
				    "baz": "42",
				    "flag": True,
				    "extra": 42,
				}

				self.assertRaises(_snake_case			,parser.parse_dict			,_snake_case			,allow_extra_keys=_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      List[Any]						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      Any						=  {
				    "foo": 12,
				    "bar": 3.14,
				    "baz": "42",
				    "flag": True,
				}
				with tempfile.TemporaryDirectory() as tmp_dir:
					UpperCAmelCase_     :      List[Any]						=  os.path.join(_snake_case			,"temp_json"     )
					os.mkdir(_snake_case     )
					with open(temp_local_path + ".json"			,"w+"     ) as f:
						json.dump(_snake_case			,_snake_case     )
					UpperCAmelCase_     :      str						=  parser.parse_yaml_file(Path(temp_local_path + ".json"     )     )[0]

				UpperCAmelCase_     :      Union[str, Any]						=  BasicExample(**_snake_case     )
				self.assertEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  HfArgumentParser(_snake_case     )

				UpperCAmelCase_     :      int						=  {
				    "foo": 12,
				    "bar": 3.14,
				    "baz": "42",
				    "flag": True,
				}
				with tempfile.TemporaryDirectory() as tmp_dir:
					UpperCAmelCase_     :      Dict						=  os.path.join(_snake_case			,"temp_yaml"     )
					os.mkdir(_snake_case     )
					with open(temp_local_path + ".yaml"			,"w+"     ) as f:
						yaml.dump(_snake_case			,_snake_case     )
					UpperCAmelCase_     :      List[Any]						=  parser.parse_yaml_file(Path(temp_local_path + ".yaml"     )     )[0]
				UpperCAmelCase_     :      str						=  BasicExample(**_snake_case     )
				self.assertEqual(_snake_case			,_snake_case     )






			def 		UpperCamelCase__							(  self     ):
				UpperCAmelCase_     :      Dict						=  HfArgumentParser(_snake_case     )
				self.assertIsNotNone(_snake_case     )









def        __lowerCAmelCase		(	__lowerCamelCase						:     int					, __lowerCamelCase						:     int						)	->    bool:
					return numa ^ numa < 0


if __name__ == "__main__":
				import doctest

				doctest.testmod()




