





'''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
lowercase__       : Optional[Any]         =       sys.version_info >= (3, 10)






def 			_lowerCAmelCase     (    __snake_case    :					Union[str, Any]=None					,				__snake_case    :					int=None     )	->	str:
     return field(default_factory=lambda: default					,				metadata=__snake_case     )


@dataclass
class 					SCREAMING_SNAKE_CASE       :
     lowerCAmelCase						     =			42
     lowerCAmelCase						     =			42
     lowerCAmelCase						     =			42
     lowerCAmelCase						     =			42




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




@dataclass
class 					SCREAMING_SNAKE_CASE       :
     lowerCAmelCase						     =			False
     lowerCAmelCase						     =			True
     lowerCAmelCase						     =			None




class 					SCREAMING_SNAKE_CASE       (a__				):
     lowerCAmelCase						     =			'''titi'''
     lowerCAmelCase						     =			'''toto'''




class 					SCREAMING_SNAKE_CASE       (a__				):
     lowerCAmelCase						     =			'''titi'''
     lowerCAmelCase						     =			'''toto'''
     lowerCAmelCase						     =			42




@dataclass
class 					SCREAMING_SNAKE_CASE       :
     lowerCAmelCase						     =			"toto"


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Tuple						=			BasicEnum(self.foo)




@dataclass
class 					SCREAMING_SNAKE_CASE       :
     lowerCAmelCase						     =			"toto"


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					List[Any]						=			MixedTypeEnum(self.foo)




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




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




@dataclass
class 					SCREAMING_SNAKE_CASE       :
     lowerCAmelCase						     =			field()
     lowerCAmelCase						     =			field()
     lowerCAmelCase						     =			field()


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					List[Any]						=			BasicEnum(self.required_enum)




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


if is_python_no_less_than_3_10:


  @dataclass
  class 					SCREAMING_SNAKE_CASE       :
       lowerCAmelCase						     =			False
       lowerCAmelCase						     =			True
       lowerCAmelCase						     =			None




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







class 					SCREAMING_SNAKE_CASE       (unittest.TestCase				):


     def 				SCREAMING_SNAKE_CASE    (		self		,      _UpperCAmelCase		,      _UpperCAmelCase):

          '''simple docstring'''






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

               self.assertEqual(_UpperCAmelCase		,      _UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[Any]						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					int						=			argparse.ArgumentParser()
          expected.add_argument('--foo'		,      type=_UpperCAmelCase		,      required=_UpperCAmelCase)
          expected.add_argument('--bar'		,      type=_UpperCAmelCase		,      required=_UpperCAmelCase)
          expected.add_argument('--baz'		,      type=_UpperCAmelCase		,      required=_UpperCAmelCase)
          expected.add_argument('--flag'		,      type=_UpperCAmelCase		,      default=_UpperCAmelCase		,      const=_UpperCAmelCase		,      nargs='?')
          self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)

          __A		:					int						=			['--foo', '1', '--baz', 'quux', '--bar', '0.5']
          ((__A)					,)		:					Any						=			parser.parse_args_into_dataclasses(_UpperCAmelCase		,      look_for_args_file=_UpperCAmelCase)
          self.assertFalse(example.flag)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[int]						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					List[str]						=			argparse.ArgumentParser()
          expected.add_argument('--foo'		,      default=42		,      type=_UpperCAmelCase)
          expected.add_argument('--baz'		,      default='toto'		,      type=_UpperCAmelCase		,      help='help message')
          self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Union[str, Any]						=			argparse.ArgumentParser()
          expected.add_argument('--foo'		,      type=_UpperCAmelCase		,      default=_UpperCAmelCase		,      const=_UpperCAmelCase		,      nargs='?')
          expected.add_argument('--baz'		,      type=_UpperCAmelCase		,      default=_UpperCAmelCase		,      const=_UpperCAmelCase		,      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=_UpperCAmelCase		,      dest='baz')
          expected.add_argument('--opt'		,      type=_UpperCAmelCase		,      default=_UpperCAmelCase)

          __A		:					str						=			[WithDefaultBoolExample]
          if is_python_no_less_than_3_10:
               dataclass_types.append(_UpperCAmelCase)

          for dataclass_type in dataclass_types:
               __A		:					Tuple						=			HfArgumentParser(_UpperCAmelCase)
               self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)

               __A		:					str						=			parser.parse_args([])
               self.assertEqual(_UpperCAmelCase		,      Namespace(foo=_UpperCAmelCase		,      baz=_UpperCAmelCase		,      opt=_UpperCAmelCase))

               __A		:					Tuple						=			parser.parse_args(['--foo', '--no_baz'])
               self.assertEqual(_UpperCAmelCase		,      Namespace(foo=_UpperCAmelCase		,      baz=_UpperCAmelCase		,      opt=_UpperCAmelCase))

               __A		:					Optional[Any]						=			parser.parse_args(['--foo', '--baz'])
               self.assertEqual(_UpperCAmelCase		,      Namespace(foo=_UpperCAmelCase		,      baz=_UpperCAmelCase		,      opt=_UpperCAmelCase))

               __A		:					Optional[int]						=			parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True'])
               self.assertEqual(_UpperCAmelCase		,      Namespace(foo=_UpperCAmelCase		,      baz=_UpperCAmelCase		,      opt=_UpperCAmelCase))

               __A		:					List[Any]						=			parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False'])
               self.assertEqual(_UpperCAmelCase		,      Namespace(foo=_UpperCAmelCase		,      baz=_UpperCAmelCase		,      opt=_UpperCAmelCase))


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[Any]						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					Tuple						=			argparse.ArgumentParser()
          expected.add_argument(
              '--foo'		,      default='toto'		,      choices=['titi', 'toto', 42]		,      type=make_choice_type_function(['titi', 'toto', 42])		,      )
          self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)

          __A		:					int						=			parser.parse_args([])
          self.assertEqual(args.foo		,      'toto')
          __A		:					Optional[Any]						=			parser.parse_args_into_dataclasses([])[0]
          self.assertEqual(enum_ex.foo		,      MixedTypeEnum.toto)

          __A		:					Union[str, Any]						=			parser.parse_args(['--foo', 'titi'])
          self.assertEqual(args.foo		,      'titi')
          __A		:					List[Any]						=			parser.parse_args_into_dataclasses(['--foo', 'titi'])[0]
          self.assertEqual(enum_ex.foo		,      MixedTypeEnum.titi)

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


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          @dataclass
          class 					SCREAMING_SNAKE_CASE       :
               lowerCAmelCase						     =			"toto"




          __A		:					str						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					Optional[Any]						=			argparse.ArgumentParser()
          expected.add_argument(
              '--foo'		,      default='toto'		,      choices=('titi', 'toto', 42)		,      type=make_choice_type_function(['titi', 'toto', 42])		,      )
          self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)

          __A		:					Dict						=			parser.parse_args([])
          self.assertEqual(args.foo		,      'toto')

          __A		:					Optional[int]						=			parser.parse_args(['--foo', 'titi'])
          self.assertEqual(args.foo		,      'titi')

          __A		:					Optional[Any]						=			parser.parse_args(['--foo', '42'])
          self.assertEqual(args.foo		,      42)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Tuple						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					Union[str, Any]						=			argparse.ArgumentParser()
          expected.add_argument('--foo_int'		,      nargs='+'		,      default=[]		,      type=_UpperCAmelCase)
          expected.add_argument('--bar_int'		,      nargs='+'		,      default=[1, 2, 3]		,      type=_UpperCAmelCase)
          expected.add_argument('--foo_str'		,      nargs='+'		,      default=['Hallo', 'Bonjour', 'Hello']		,      type=_UpperCAmelCase)
          expected.add_argument('--foo_float'		,      nargs='+'		,      default=[0.1, 0.2, 0.3]		,      type=_UpperCAmelCase)

          self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)

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

          __A		:					Optional[int]						=			parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split())
          self.assertEqual(_UpperCAmelCase		,      Namespace(foo_int=[1]		,      bar_int=[2, 3]		,      foo_str=['a', 'b', 'c']		,      foo_float=[0.1, 0.7]))


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[int]						=			argparse.ArgumentParser()
          expected.add_argument('--foo'		,      default=_UpperCAmelCase		,      type=_UpperCAmelCase)
          expected.add_argument('--bar'		,      default=_UpperCAmelCase		,      type=_UpperCAmelCase		,      help='help message')
          expected.add_argument('--baz'		,      default=_UpperCAmelCase		,      type=_UpperCAmelCase)
          expected.add_argument('--ces'		,      nargs='+'		,      default=[]		,      type=_UpperCAmelCase)
          expected.add_argument('--des'		,      nargs='+'		,      default=[]		,      type=_UpperCAmelCase)

          __A		:					Optional[int]						=			[OptionalExample]
          if is_python_no_less_than_3_10:
               dataclass_types.append(_UpperCAmelCase)

          for dataclass_type in dataclass_types:
               __A		:					Dict						=			HfArgumentParser(_UpperCAmelCase)

               self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)

               __A		:					Union[str, Any]						=			parser.parse_args([])
               self.assertEqual(_UpperCAmelCase		,      Namespace(foo=_UpperCAmelCase		,      bar=_UpperCAmelCase		,      baz=_UpperCAmelCase		,      ces=[]		,      des=[]))

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


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Tuple						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					Optional[int]						=			argparse.ArgumentParser()
          expected.add_argument('--required_list'		,      nargs='+'		,      type=_UpperCAmelCase		,      required=_UpperCAmelCase)
          expected.add_argument('--required_str'		,      type=_UpperCAmelCase		,      required=_UpperCAmelCase)
          expected.add_argument(
              '--required_enum'		,      type=make_choice_type_function(['titi', 'toto'])		,      choices=['titi', 'toto']		,      required=_UpperCAmelCase		,      )
          self.argparsersEqual(_UpperCAmelCase		,      _UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[int]						=			HfArgumentParser(_UpperCAmelCase)

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


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Tuple						=			HfArgumentParser(_UpperCAmelCase)

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

          __A		:					str						=			parser.parse_dict(_UpperCAmelCase)[0]
          __A		:					Optional[Any]						=			BasicExample(**_UpperCAmelCase)
          self.assertEqual(_UpperCAmelCase		,      _UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					List[str]						=			HfArgumentParser(_UpperCAmelCase)

          __A		:					List[Any]						=			{
              'foo': 12,
              'bar': 3.14,
              'baz': '42',
              'flag': True,
              'extra': 42,
          }

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


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Any						=			HfArgumentParser(_UpperCAmelCase)

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

          __A		:					str						=			BasicExample(**_UpperCAmelCase)
          self.assertEqual(_UpperCAmelCase		,      _UpperCAmelCase)


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Tuple						=			HfArgumentParser(_UpperCAmelCase)

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


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[Any]						=			HfArgumentParser(_UpperCAmelCase)
          self.assertIsNotNone(_UpperCAmelCase)






'''simple docstring'''




def 			_lowerCAmelCase     (    __snake_case    :					int					,				__snake_case    :					int					,				__snake_case    :					int     )	->	float:
     __A		:					Dict						=			(num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
     # formula for sum of series
     return total






def 			_lowerCAmelCase     (    )	->	Union[str, Any]:
     print(sum_of_series(1					,				1					,				10     )     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()