
"""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
UpperCAmelCase        =				sys.version_info >= (3, 1_0)




def __magic_name__	(				_lowerCamelCase:		List[str]=None,					_lowerCamelCase:		Union[str, Any]=None			)					->						Any:

	'''simple docstring'''




	return field(default_factory=lambda: default,					metadata=_lowerCamelCase			)



@dataclass
class 			lowercase					:
			lowercase        =     42
			lowercase        =     42
			lowercase        =     42
			lowercase        =     42





@dataclass
class 			lowercase					:
			lowercase        =     42
			lowercase        =     field(default='''toto'''   ,metadata={'''help''': '''help message'''}		)





@dataclass
class 			lowercase					:
			lowercase        =     False
			lowercase        =     True
			lowercase        =     None





class 			lowercase					( lowercase__		):
			lowercase        =     '''titi'''
			lowercase        =     '''toto'''





class 			lowercase					( lowercase__		):
			lowercase        =     '''titi'''
			lowercase        =     '''toto'''
			lowercase        =     42





@dataclass
class 			lowercase					:
			lowercase        =     "toto"






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  BasicEnum(self.foo			)





@dataclass
class 			lowercase					:
			lowercase        =     "toto"






			def 					UpperCAmelCase							(self  :	int			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  MixedTypeEnum(self.foo			)





@dataclass
class 			lowercase					:
			lowercase        =     None
			lowercase        =     field(default=lowercase__   ,metadata={'''help''': '''help message'''}		)
			lowercase        =     None
			lowercase        =     list_field(default=[]		)
			lowercase        =     list_field(default=[]		)





@dataclass
class 			lowercase					:
			lowercase        =     list_field(default=[]		)
			lowercase        =     list_field(default=[1, 2, 3]		)
			lowercase        =     list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']		)
			lowercase        =     list_field(default=[0.1, 0.2, 0.3]		)





@dataclass
class 			lowercase					:
			lowercase        =     field()
			lowercase        =     field()
			lowercase        =     field()






			def 					UpperCAmelCase							(self  :	Any			)       ->	Any:





				"""simple docstring"""


				lowerCAmelCase												=  BasicEnum(self.required_enum			)





@dataclass
class 			lowercase					:
			lowercase        =     42
			lowercase        =     field()
			lowercase        =     None
			lowercase        =     field(default='''toto'''   ,metadata={'''help''': '''help message'''}		)
			lowercase        =     list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']		)


if is_python_no_less_than_3_10:



					@dataclass
					class 			lowercase					:
								lowercase        =     False
								lowercase        =     True
								lowercase        =     None





					@dataclass
					class 			lowercase					:
								lowercase        =     None
								lowercase        =     field(default=lowercase__   ,metadata={'''help''': '''help message'''}		)
								lowercase        =     None
								lowercase        =     list_field(default=[]		)
								lowercase        =     list_field(default=[]		)



class 			lowercase					( unittest.TestCase		):






			def 					UpperCAmelCase							(self  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	argparse.ArgumentParser      ,SCREAMING_SNAKE_CASE_  :	argparse.ArgumentParser			)       ->	Optional[Any]:





				"""simple docstring"""


				self.assertEqual(len(a._actions			)      ,len(b._actions			)			)
				for x, y in zip(a._actions      ,b._actions			):
					lowerCAmelCase												=  {k: v for k, v in vars(SCREAMING_SNAKE_CASE_			).items() if k != '''container'''}
					lowerCAmelCase												=  {k: v for k, v in vars(SCREAMING_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'''      ,SCREAMING_SNAKE_CASE_			) and yy.get('''choices'''      ,SCREAMING_SNAKE_CASE_			):
						for expected_choice in yy["choices"] + xx["choices"]:
							self.assertEqual(xx['''type'''](SCREAMING_SNAKE_CASE_			)      ,yy['''type'''](SCREAMING_SNAKE_CASE_			)			)
						del xx["type"], yy["type"]

					self.assertEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument('''--foo'''      ,type=SCREAMING_SNAKE_CASE_      ,required=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--bar'''      ,type=SCREAMING_SNAKE_CASE_      ,required=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--baz'''      ,type=SCREAMING_SNAKE_CASE_      ,required=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--flag'''      ,type=SCREAMING_SNAKE_CASE_      ,default=SCREAMING_SNAKE_CASE_      ,const=SCREAMING_SNAKE_CASE_      ,nargs='''?'''			)
				self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  ['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
				((lowerCAmelCase)							,       )												=  parser.parse_args_into_dataclasses(SCREAMING_SNAKE_CASE_      ,look_for_args_file=SCREAMING_SNAKE_CASE_			)
				self.assertFalse(example.flag			)






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument('''--foo'''      ,default=42      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--baz'''      ,default='''toto'''      ,type=SCREAMING_SNAKE_CASE_      ,help='''help message'''			)
				self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument('''--foo'''      ,type=SCREAMING_SNAKE_CASE_      ,default=SCREAMING_SNAKE_CASE_      ,const=SCREAMING_SNAKE_CASE_      ,nargs='''?'''			)
				expected.add_argument('''--baz'''      ,type=SCREAMING_SNAKE_CASE_      ,default=SCREAMING_SNAKE_CASE_      ,const=SCREAMING_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=SCREAMING_SNAKE_CASE_      ,dest='''baz'''			)
				expected.add_argument('''--opt'''      ,type=SCREAMING_SNAKE_CASE_      ,default=SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  [WithDefaultBoolExample]
				if is_python_no_less_than_3_10:
					dataclass_types.append(SCREAMING_SNAKE_CASE_			)

				for dataclass_type in dataclass_types:
					lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)
					self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

					lowerCAmelCase												=  parser.parse_args([]			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=SCREAMING_SNAKE_CASE_      ,baz=SCREAMING_SNAKE_CASE_      ,opt=SCREAMING_SNAKE_CASE_			)			)

					lowerCAmelCase												=  parser.parse_args(['''--foo''', '''--no_baz''']			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=SCREAMING_SNAKE_CASE_      ,baz=SCREAMING_SNAKE_CASE_      ,opt=SCREAMING_SNAKE_CASE_			)			)

					lowerCAmelCase												=  parser.parse_args(['''--foo''', '''--baz''']			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=SCREAMING_SNAKE_CASE_      ,baz=SCREAMING_SNAKE_CASE_      ,opt=SCREAMING_SNAKE_CASE_			)			)

					lowerCAmelCase												=  parser.parse_args(['''--foo''', '''True''', '''--baz''', '''True''', '''--opt''', '''True''']			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=SCREAMING_SNAKE_CASE_      ,baz=SCREAMING_SNAKE_CASE_      ,opt=SCREAMING_SNAKE_CASE_			)			)

					lowerCAmelCase												=  parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False''']			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=SCREAMING_SNAKE_CASE_      ,baz=SCREAMING_SNAKE_CASE_      ,opt=SCREAMING_SNAKE_CASE_			)			)






			def 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument(
				    '''--foo'''      ,default='''toto'''      ,choices=['''titi''', '''toto''', 42]      ,type=make_choice_type_function(['''titi''', '''toto''', 42]			)      ,)
				self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  parser.parse_args([]			)
				self.assertEqual(args.foo      ,'''toto'''			)
				lowerCAmelCase												=  parser.parse_args_into_dataclasses([]			)[0]
				self.assertEqual(enum_ex.foo      ,MixedTypeEnum.toto			)

				lowerCAmelCase												=  parser.parse_args(['''--foo''', '''titi''']			)
				self.assertEqual(args.foo      ,'''titi'''			)
				lowerCAmelCase												=  parser.parse_args_into_dataclasses(['''--foo''', '''titi''']			)[0]
				self.assertEqual(enum_ex.foo      ,MixedTypeEnum.titi			)

				lowerCAmelCase												=  parser.parse_args(['''--foo''', '''42''']			)
				self.assertEqual(args.foo      ,42			)
				lowerCAmelCase												=  parser.parse_args_into_dataclasses(['''--foo''', '''42''']			)[0]
				self.assertEqual(enum_ex.foo      ,MixedTypeEnum.fourtytwo			)






			def 					UpperCAmelCase							(self  :	str			)       ->	str:





				"""simple docstring"""


				@dataclass
				class 			lowercase					:
							lowercase        =     "toto"





				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument(
				    '''--foo'''      ,default='''toto'''      ,choices=('''titi''', '''toto''', 42)      ,type=make_choice_type_function(['''titi''', '''toto''', 42]			)      ,)
				self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  parser.parse_args([]			)
				self.assertEqual(args.foo      ,'''toto'''			)

				lowerCAmelCase												=  parser.parse_args(['''--foo''', '''titi''']			)
				self.assertEqual(args.foo      ,'''titi'''			)

				lowerCAmelCase												=  parser.parse_args(['''--foo''', '''42''']			)
				self.assertEqual(args.foo      ,42			)






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument('''--foo_int'''      ,nargs='''+'''      ,default=[]      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--bar_int'''      ,nargs='''+'''      ,default=[1, 2, 3]      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--foo_str'''      ,nargs='''+'''      ,default=['''Hallo''', '''Bonjour''', '''Hello''']      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--foo_float'''      ,nargs='''+'''      ,default=[0.1, 0.2, 0.3]      ,type=SCREAMING_SNAKE_CASE_			)

				self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  parser.parse_args([]			)
				self.assertEqual(
				    SCREAMING_SNAKE_CASE_      ,Namespace(foo_int=[]      ,bar_int=[1, 2, 3]      ,foo_str=['''Hallo''', '''Bonjour''', '''Hello''']      ,foo_float=[0.1, 0.2, 0.3]			)      ,)

				lowerCAmelCase												=  parser.parse_args('''--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'''.split()			)
				self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo_int=[1]      ,bar_int=[2, 3]      ,foo_str=['''a''', '''b''', '''c''']      ,foo_float=[0.1, 0.7]			)			)






			def 					UpperCAmelCase							(self  :	List[str]			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument('''--foo'''      ,default=SCREAMING_SNAKE_CASE_      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--bar'''      ,default=SCREAMING_SNAKE_CASE_      ,type=SCREAMING_SNAKE_CASE_      ,help='''help message'''			)
				expected.add_argument('''--baz'''      ,default=SCREAMING_SNAKE_CASE_      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--ces'''      ,nargs='''+'''      ,default=[]      ,type=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--des'''      ,nargs='''+'''      ,default=[]      ,type=SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  [OptionalExample]
				if is_python_no_less_than_3_10:
					dataclass_types.append(SCREAMING_SNAKE_CASE_			)

				for dataclass_type in dataclass_types:
					lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

					self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

					lowerCAmelCase												=  parser.parse_args([]			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=SCREAMING_SNAKE_CASE_      ,bar=SCREAMING_SNAKE_CASE_      ,baz=SCREAMING_SNAKE_CASE_      ,ces=[]      ,des=[]			)			)

					lowerCAmelCase												=  parser.parse_args('''--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'''.split()			)
					self.assertEqual(SCREAMING_SNAKE_CASE_      ,Namespace(foo=12      ,bar=3.14      ,baz='''42'''      ,ces=['''a''', '''b''', '''c''']      ,des=[1, 2, 3]			)			)






			def 					UpperCAmelCase							(self  :	int			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  argparse.ArgumentParser()
				expected.add_argument('''--required_list'''      ,nargs='''+'''      ,type=SCREAMING_SNAKE_CASE_      ,required=SCREAMING_SNAKE_CASE_			)
				expected.add_argument('''--required_str'''      ,type=SCREAMING_SNAKE_CASE_      ,required=SCREAMING_SNAKE_CASE_			)
				expected.add_argument(
				    '''--required_enum'''      ,type=make_choice_type_function(['''titi''', '''toto''']			)      ,choices=['''titi''', '''toto''']      ,required=SCREAMING_SNAKE_CASE_      ,)
				self.argparsersEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

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






			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  {
				    '''foo''': 12,
				    '''bar''': 3.14,
				    '''baz''': '''42''',
				    '''flag''': True,
				}

				lowerCAmelCase												=  parser.parse_dict(SCREAMING_SNAKE_CASE_			)[0]
				lowerCAmelCase												=  BasicExample(**SCREAMING_SNAKE_CASE_			)
				self.assertEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	str			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  {
				    '''foo''': 12,
				    '''bar''': 3.14,
				    '''baz''': '''42''',
				    '''flag''': True,
				    '''extra''': 42,
				}

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






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

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

				lowerCAmelCase												=  BasicExample(**SCREAMING_SNAKE_CASE_			)
				self.assertEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	int			)       ->	Any:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  {
				    '''foo''': 12,
				    '''bar''': 3.14,
				    '''baz''': '''42''',
				    '''flag''': True,
				}
				with tempfile.TemporaryDirectory() as tmp_dir:
					lowerCAmelCase												=  os.path.join(SCREAMING_SNAKE_CASE_      ,'''temp_yaml'''			)
					os.mkdir(SCREAMING_SNAKE_CASE_			)
					with open(temp_local_path + '''.yaml'''      ,'''w+'''			) as f:
						yaml.dump(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)
					lowerCAmelCase												=  parser.parse_yaml_file(Path(temp_local_path + '''.yaml'''			)			)[0]
				lowerCAmelCase												=  BasicExample(**SCREAMING_SNAKE_CASE_			)
				self.assertEqual(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Any			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  HfArgumentParser(SCREAMING_SNAKE_CASE_			)
				self.assertIsNotNone(SCREAMING_SNAKE_CASE_			)




"""simple docstring"""






def __magic_name__	(				_lowerCamelCase:		Tuple,					_lowerCamelCase:		Any			)					->						Optional[Any]:

	'''simple docstring'''




	lowerCAmelCase												=  [1]
	for i in range(2,					_lowerCamelCase			):
		factorials.append(factorials[-1] * i			)
	assert 0 <= k < factorials[-1] * n, "k out of bounds"

	lowerCAmelCase												=  []
	lowerCAmelCase												=  list(range(_lowerCamelCase			)			)

	# Find permutation
	while factorials:
		lowerCAmelCase												=  factorials.pop()
		lowerCAmelCase							,       lowerCAmelCase												=  divmod(_lowerCamelCase,					_lowerCamelCase			)
		permutation.append(elements[number]			)
		elements.remove(elements[number]			)
	permutation.append(elements[0]			)

	return permutation


if __name__ == "__main__":
					import doctest

					doctest.testmod()


