


'''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_      :		int          =		sys.version_info >= (3, 10)


def    UpperCAmelCase_  (       A=None		,	A=None      ):
   '''simple docstring'''





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







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: int
 __lowerCAmelCase						: float
 __lowerCAmelCase						: str
 __lowerCAmelCase						: bool







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: int							  =		42
 __lowerCAmelCase						: str							  =		field(default="""toto"""			,							metadata={"""help""": """help message"""}  )







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: bool							  =		False
 __lowerCAmelCase						: bool							  =		True
 __lowerCAmelCase						: Optional[bool]							  =		None







class 					a			(				snake_case__  ):
 '''simple docstring'''




 __lowerCAmelCase						: List[str]							  =		"""titi"""
 __lowerCAmelCase						: Optional[int]							  =		"""toto"""







class 					a			(				snake_case__  ):
 '''simple docstring'''




 __lowerCAmelCase						: Any							  =		"""titi"""
 __lowerCAmelCase						: List[str]							  =		"""toto"""
 __lowerCAmelCase						: Optional[int]							  =		42







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: BasicEnum							  =		"toto"




 def   __UpperCamelCase   (    self      )      ->    Union[str, Any]:
    _a					:  int						=  BasicEnum(self.foo      )







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: MixedTypeEnum							  =		"toto"




 def   __UpperCamelCase   (    self      )      ->    Any:
    _a					:  Dict						=  MixedTypeEnum(self.foo      )







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: Optional[int]							  =		None
 __lowerCAmelCase						: Optional[float]							  =		field(default=snake_case__			,							metadata={"""help""": """help message"""}  )
 __lowerCAmelCase						: Optional[str]							  =		None
 __lowerCAmelCase						: Optional[List[str]]							  =		list_field(default=[]  )
 __lowerCAmelCase						: Optional[List[int]]							  =		list_field(default=[]  )







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: List[int]							  =		list_field(default=[]  )
 __lowerCAmelCase						: List[int]							  =		list_field(default=[1, 2, 3]  )
 __lowerCAmelCase						: List[str]							  =		list_field(default=["""Hallo""", """Bonjour""", """Hello"""]  )
 __lowerCAmelCase						: List[float]							  =		list_field(default=[0.1, 0.2, 0.3]  )







@dataclass
class 					a			:
 '''simple docstring'''




 __lowerCAmelCase						: List[int]							  =		field()
 __lowerCAmelCase						: str							  =		field()
 __lowerCAmelCase						: BasicEnum							  =		field()




 def   __UpperCamelCase   (    self      )      ->    Dict:
    _a					:  Union[str, Any]						=  BasicEnum(self.required_enum      )







@dataclass
class 					a			:
 '''simple docstring'''




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


if is_python_no_less_than_3_10:







 @dataclass
 class 					a			:
  '''simple docstring'''




  __lowerCAmelCase						: bool							  =		False
  __lowerCAmelCase						: bool							  =		True
  __lowerCAmelCase						: bool | None							  =		None







 @dataclass
 class 					a			:
  '''simple docstring'''




  __lowerCAmelCase						: int | None							  =		None
  __lowerCAmelCase						: float | None							  =		field(default=snake_case__			,							metadata={"""help""": """help message"""}  )
  __lowerCAmelCase						: str | None							  =		None
  __lowerCAmelCase						: list[str] | None							  =		list_field(default=[]  )
  __lowerCAmelCase						: list[int] | None							  =		list_field(default=[]  )







class 					a			(				unittest.TestCase  ):
 '''simple docstring'''




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_      )      ->    Union[str, Any]:
    self.assertEqual(len(a._actions      )		,      len(b._actions      )      )
    for x, y in zip(a._actions		,      b._actions      ):
       _a					:  Optional[int]						=  {k: v for k, v in vars(lowerCamelCase_      ).items() if k != 'container'}
       _a					:  Optional[int]						=  {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   __UpperCamelCase   (    self      )      ->    str:
    _a					:  Tuple						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  Dict						=  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_      )

    _a					:  Optional[int]						=  ['--foo', '1', '--baz', 'quux', '--bar', '0.5']
    ((_a)		,						)					:  Union[str, Any]						=  parser.parse_args_into_dataclasses(lowerCamelCase_		,      look_for_args_file=lowerCamelCase_      )
    self.assertFalse(example.flag      )




 def   __UpperCamelCase   (    self      )      ->    int:
    _a					:  int						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  Any						=  argparse.ArgumentParser()
    expected.add_argument('--foo'		,      default=4_2		,      type=lowerCamelCase_      )
    expected.add_argument('--baz'		,      default='toto'		,      type=lowerCamelCase_		,      help='help message'      )
    self.argparsersEqual(lowerCamelCase_		,      lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    List[str]:
    _a					:  Dict						=  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_      )

    _a					:  Any						=  [WithDefaultBoolExample]
    if is_python_no_less_than_3_10:
       dataclass_types.append(lowerCamelCase_      )

    for dataclass_type in dataclass_types:
       _a					:  List[str]						=  HfArgumentParser(lowerCamelCase_      )
       self.argparsersEqual(lowerCamelCase_		,      lowerCamelCase_      )

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

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

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

       _a					:  Any						=  parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']      )
       self.assertEqual(lowerCamelCase_		,      Namespace(foo=lowerCamelCase_		,      baz=lowerCamelCase_		,      opt=lowerCamelCase_      )      )

       _a					:  Optional[int]						=  parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']      )
       self.assertEqual(lowerCamelCase_		,      Namespace(foo=lowerCamelCase_		,      baz=lowerCamelCase_		,      opt=lowerCamelCase_      )      )




 def   __UpperCamelCase   (    self      )      ->    Tuple:
    _a					:  Any						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  Union[str, Any]						=  argparse.ArgumentParser()
    expected.add_argument(
        '--foo'		,      default='toto'		,      choices=['titi', 'toto', 4_2]		,      type=make_choice_type_function(['titi', 'toto', 4_2]      )		,      )
    self.argparsersEqual(lowerCamelCase_		,      lowerCamelCase_      )

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

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

    _a					:  int						=  parser.parse_args(['--foo', '42']      )
    self.assertEqual(args.foo		,      4_2      )
    _a					:  Optional[int]						=  parser.parse_args_into_dataclasses(['--foo', '42']      )[0]
    self.assertEqual(enum_ex.foo		,      MixedTypeEnum.fourtytwo      )




 def   __UpperCamelCase   (    self      )      ->    str:







    @dataclass
    class 					a			:
     '''simple docstring'''




     __lowerCAmelCase						: Literal["titi", "toto", 42]							  =		"toto"





    _a					:  Optional[Any]						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  str						=  argparse.ArgumentParser()
    expected.add_argument(
        '--foo'		,      default='toto'		,      choices=('titi', 'toto', 4_2)		,      type=make_choice_type_function(['titi', 'toto', 4_2]      )		,      )
    self.argparsersEqual(lowerCamelCase_		,      lowerCamelCase_      )

    _a					:  List[Any]						=  parser.parse_args([]      )
    self.assertEqual(args.foo		,      'toto'      )

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

    _a					:  Any						=  parser.parse_args(['--foo', '42']      )
    self.assertEqual(args.foo		,      4_2      )




 def   __UpperCamelCase   (    self      )      ->    Dict:
    _a					:  str						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  Tuple						=  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_      )

    _a					:  int						=  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]      )		,      )

    _a					:  Any						=  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   __UpperCamelCase   (    self      )      ->    Union[str, Any]:
    _a					:  List[str]						=  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_      )

    _a					:  Any						=  [OptionalExample]
    if is_python_no_less_than_3_10:
       dataclass_types.append(lowerCamelCase_      )

    for dataclass_type in dataclass_types:
       _a					:  List[str]						=  HfArgumentParser(lowerCamelCase_      )

       self.argparsersEqual(lowerCamelCase_		,      lowerCamelCase_      )

       _a					:  Optional[int]						=  parser.parse_args([]      )
       self.assertEqual(lowerCamelCase_		,      Namespace(foo=lowerCamelCase_		,      bar=lowerCamelCase_		,      baz=lowerCamelCase_		,      ces=[]		,      des=[]      )      )

       _a					:  Optional[int]						=  parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split()      )
       self.assertEqual(lowerCamelCase_		,      Namespace(foo=1_2		,      bar=3.14		,      baz='42'		,      ces=['a', 'b', 'c']		,      des=[1, 2, 3]      )      )




 def   __UpperCamelCase   (    self      )      ->    Tuple:
    _a					:  Union[str, Any]						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  List[Any]						=  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   __UpperCamelCase   (    self      )      ->    Optional[int]:
    _a					:  Optional[Any]						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  Union[str, Any]						=  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   __UpperCamelCase   (    self      )      ->    List[str]:
    _a					:  List[Any]						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  str						=  {
        'foo': 1_2,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
    }

    _a					:  Dict						=  parser.parse_dict(lowerCamelCase_      )[0]
    _a					:  List[Any]						=  BasicExample(**lowerCamelCase_      )
    self.assertEqual(lowerCamelCase_		,      lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    Tuple:
    _a					:  str						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  List[Any]						=  {
        'foo': 1_2,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
        'extra': 4_2,
    }

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




 def   __UpperCamelCase   (    self      )      ->    Optional[Any]:
    _a					:  str						=  HfArgumentParser(lowerCamelCase_      )

    _a					:  List[Any]						=  {
        'foo': 1_2,
        'bar': 3.14,
        'baz': '42',
        'flag': True,
    }
    with tempfile.TemporaryDirectory() as tmp_dir:
       _a					:  int						=  os.path.join(lowerCamelCase_		,      'temp_json'      )
       os.mkdir(lowerCamelCase_      )
       with open(temp_local_path + '.json'		,      'w+'      ) as f:
          json.dump(lowerCamelCase_		,      lowerCamelCase_      )
       _a					:  Optional[Any]						=  parser.parse_yaml_file(Path(temp_local_path + '.json'      )      )[0]

    _a					:  Optional[int]						=  BasicExample(**lowerCamelCase_      )
    self.assertEqual(lowerCamelCase_		,      lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    Optional[int]:
    _a					:  Tuple						=  HfArgumentParser(lowerCamelCase_      )

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




 def   __UpperCamelCase   (    self      )      ->    Dict:
    _a					:  Union[str, Any]						=  HfArgumentParser(lowerCamelCase_      )
    self.assertIsNotNone(lowerCamelCase_      )






'''simple docstring'''




from ..utils import DummyObject, requires_backends







class 					a			(				metaclass=snake_case__  ):
 '''simple docstring'''




 __lowerCAmelCase						: Union[str, Any]							  =		["""note_seq"""]




 def __init__(    self		,      *lowerCamelCase_		,      **lowerCamelCase_      )      ->    int:
    requires_backends(self		,      ['note_seq']      )




 @classmethod
 def   __UpperCamelCase   (    cls		,      *lowerCamelCase_		,      **lowerCamelCase_      )      ->    Union[str, Any]:
    requires_backends(cls		,      ['note_seq']      )




 @classmethod
 def   __UpperCamelCase   (    cls		,      *lowerCamelCase_		,      **lowerCamelCase_      )      ->    List[str]:
    requires_backends(cls		,      ['note_seq']      )


