




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
__magic_name__  :  Union[str, Any]					=       sys.version_info >= (3, 10)
def 		a_							( __lowerCAmelCase=None   , __lowerCAmelCase=None				):
  return field(default_factory=lambda: default   , metadata=__lowerCAmelCase				)





@dataclass
class     SCREAMING_SNAKE_CASE__		:
     lowercase_ :      int
     lowercase_ :      float
     lowercase_ :      str
     lowercase_ :      bool





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





@dataclass
class     SCREAMING_SNAKE_CASE__		:
     lowercase_ :      bool				= False
     lowercase_ :      bool				= True
     lowercase_ :      Optional[bool]				= None





class     SCREAMING_SNAKE_CASE__		(_a			):
     lowercase_ :      Tuple				= "titi"
     lowercase_ :      Any				= "toto"





class     SCREAMING_SNAKE_CASE__		(_a			):
     lowercase_ :      Dict				= "titi"
     lowercase_ :      str				= "toto"
     lowercase_ :      Tuple				= 42





@dataclass
class     SCREAMING_SNAKE_CASE__		:
     lowercase_ :      BasicEnum				= "toto"
     def        A__      (						self	:		List[str]						):



       """simple docstring"""
       lowerCAmelCase__										=      BasicEnum(self.foo						)





@dataclass
class     SCREAMING_SNAKE_CASE__		:
     lowercase_ :      MixedTypeEnum				= "toto"
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      MixedTypeEnum(self.foo						)





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





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





@dataclass
class     SCREAMING_SNAKE_CASE__		:
     lowercase_ :      List[int]				= field()
     lowercase_ :      str				= field()
     lowercase_ :      BasicEnum				= field()
     def        A__      (						self	:		List[str]						):



       """simple docstring"""
       lowerCAmelCase__										=      BasicEnum(self.required_enum						)





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


if is_python_no_less_than_3_10:





      @dataclass
      class     SCREAMING_SNAKE_CASE__		:
           lowercase_ :      bool				= False
           lowercase_ :      bool				= True
           lowercase_ :      bool | None				= None





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





class     SCREAMING_SNAKE_CASE__		(unittest.TestCase			):
     def        A__      (						self	:		Optional[Any]       ,						__lowerCamelCase	:		argparse.ArgumentParser       ,						__lowerCamelCase	:		argparse.ArgumentParser						):



       """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(__lowerCamelCase						).items() if k != '''container'''}
         lowerCAmelCase__										=      {k: v for k, v in vars(__lowerCamelCase						).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'''       ,						__lowerCamelCase						) and yy.get('''choices'''       ,						__lowerCamelCase						):
           for expected_choice in yy["choices"] + xx["choices"]:
             self.assertEqual(xx['''type'''](__lowerCamelCase						)       ,						yy['''type'''](__lowerCamelCase						)						)
           del xx["type"], yy["type"]

         self.assertEqual(__lowerCamelCase       ,						__lowerCamelCase						)
     def        A__      (						self	:		List[str]						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       lowerCAmelCase__										=      ['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
       ((lowerCAmelCase__)				,      )										=      parser.parse_args_into_dataclasses(__lowerCamelCase       ,						look_for_args_file=__lowerCamelCase						)
       self.assertFalse(example.flag						)
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

       lowerCAmelCase__										=      argparse.ArgumentParser()
       expected.add_argument('''--foo'''       ,						default=42       ,						type=__lowerCamelCase						)
       expected.add_argument('''--baz'''       ,						default='''toto'''       ,						type=__lowerCamelCase       ,						help='''help message'''						)
       self.argparsersEqual(__lowerCamelCase       ,						__lowerCamelCase						)
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      argparse.ArgumentParser()
       expected.add_argument('''--foo'''       ,						type=__lowerCamelCase       ,						default=__lowerCamelCase       ,						const=__lowerCamelCase       ,						nargs='''?'''						)
       expected.add_argument('''--baz'''       ,						type=__lowerCamelCase       ,						default=__lowerCamelCase       ,						const=__lowerCamelCase       ,						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=__lowerCamelCase       ,						dest='''baz'''						)
       expected.add_argument('''--opt'''       ,						type=__lowerCamelCase       ,						default=__lowerCamelCase						)

       lowerCAmelCase__										=      [WithDefaultBoolExample]
       if is_python_no_less_than_3_10:
         dataclass_types.append(__lowerCamelCase						)

       for dataclass_type in dataclass_types:
         lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)
         self.argparsersEqual(__lowerCamelCase       ,						__lowerCamelCase						)

         lowerCAmelCase__										=      parser.parse_args([]						)
         self.assertEqual(__lowerCamelCase       ,						Namespace(foo=__lowerCamelCase       ,						baz=__lowerCamelCase       ,						opt=__lowerCamelCase						)						)

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

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

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

         lowerCAmelCase__										=      parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False''']						)
         self.assertEqual(__lowerCamelCase       ,						Namespace(foo=__lowerCamelCase       ,						baz=__lowerCamelCase       ,						opt=__lowerCamelCase						)						)
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       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        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""





       @dataclass
       class     SCREAMING_SNAKE_CASE__		:
            lowercase_ :      Literal["titi", "toto", 42]				= "toto"



       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       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        A__      (						self	:		List[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       self.argparsersEqual(__lowerCamelCase       ,						__lowerCamelCase						)

       lowerCAmelCase__										=      parser.parse_args([]						)
       self.assertEqual(
           __lowerCamelCase       ,						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(__lowerCamelCase       ,						Namespace(foo_int=[1]       ,						bar_int=[2, 3]       ,						foo_str=['''a''', '''b''', '''c''']       ,						foo_float=[0.1, 0.7]						)						)
     def        A__      (						self	:		str						):



       """simple docstring"""
       lowerCAmelCase__										=      argparse.ArgumentParser()
       expected.add_argument('''--foo'''       ,						default=__lowerCamelCase       ,						type=__lowerCamelCase						)
       expected.add_argument('''--bar'''       ,						default=__lowerCamelCase       ,						type=__lowerCamelCase       ,						help='''help message'''						)
       expected.add_argument('''--baz'''       ,						default=__lowerCamelCase       ,						type=__lowerCamelCase						)
       expected.add_argument('''--ces'''       ,						nargs='''+'''       ,						default=[]       ,						type=__lowerCamelCase						)
       expected.add_argument('''--des'''       ,						nargs='''+'''       ,						default=[]       ,						type=__lowerCamelCase						)

       lowerCAmelCase__										=      [OptionalExample]
       if is_python_no_less_than_3_10:
         dataclass_types.append(__lowerCamelCase						)

       for dataclass_type in dataclass_types:
         lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

         self.argparsersEqual(__lowerCamelCase       ,						__lowerCamelCase						)

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

         lowerCAmelCase__										=      parser.parse_args('''--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'''.split()						)
         self.assertEqual(__lowerCamelCase       ,						Namespace(foo=12       ,						bar=3.14       ,						baz='''42'''       ,						ces=['''a''', '''b''', '''c''']       ,						des=[1, 2, 3]						)						)
     def        A__      (						self	:		Dict						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       lowerCAmelCase__										=      parser.parse_dict(__lowerCamelCase						)[0]
       lowerCAmelCase__										=      BasicExample(**__lowerCamelCase						)
       self.assertEqual(__lowerCamelCase       ,						__lowerCamelCase						)
     def        A__      (						self	:		str						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       self.assertRaises(__lowerCamelCase       ,						parser.parse_dict       ,						__lowerCamelCase       ,						allow_extra_keys=__lowerCamelCase						)
     def        A__      (						self	:		str						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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

       lowerCAmelCase__										=      BasicExample(**__lowerCamelCase						)
       self.assertEqual(__lowerCamelCase       ,						__lowerCamelCase						)
     def        A__      (						self	:		Dict						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)

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



     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      HfArgumentParser(__lowerCamelCase						)
       self.assertIsNotNone(__lowerCamelCase						)







from __future__ import annotations
def 		a_							( __lowerCAmelCase				):
  if not nums:
    return 0
  lowerCAmelCase__										=      nums[0]
  lowerCAmelCase__										=      0
  for num in nums[1:]:
    lowerCAmelCase__				,      lowerCAmelCase__										=      (
        max_excluding + num,
        max(__lowerCAmelCase   , __lowerCAmelCase				),
    )
  return max(__lowerCAmelCase   , __lowerCAmelCase				)


if __name__ == "__main__":
      import doctest

      doctest.testmod()

