



'''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    _SCREAMING_SNAKE_CASE  (       UpperCamelCase=None							,    UpperCamelCase=None			):



    """simple docstring"""





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






@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      Optional[Any]				=      4_2
  __lowercase							:      int				=      4_2
  __lowercase							:      Dict				=      4_2
  __lowercase							:      Union[str, Any]				=      4_2







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      Optional[int]				=      4_2
  __lowercase							:      Union[str, Any]				=      field(default='''toto'''						, metadata={'''help''': '''help message'''}     )







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      List[Any]				=      False
  __lowercase							:      Union[str, Any]				=      True
  __lowercase							:      List[str]				=      None







class        lowerCAmelCase_(				lowerCamelCase_     ):
  '''simple docstring'''




  __lowercase							:      Tuple				=      '''titi'''
  __lowercase							:      int				=      '''toto'''







class        lowerCAmelCase_(				lowerCamelCase_     ):
  '''simple docstring'''




  __lowercase							:      str				=      '''titi'''
  __lowercase							:      str				=      '''toto'''
  __lowercase							:      List[str]				=      4_2







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      Optional[int]				=      '''toto'''




  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  Union[str, Any]							      =					BasicEnum(self.foo      )







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      List[str]				=      '''toto'''




  def 							UpperCAmelCase_	(    self      )    ->		Dict:
      lowerCAmelCase__ :  int							      =					MixedTypeEnum(self.foo      )







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      Tuple				=      None
  __lowercase							:      Optional[int]				=      field(default=lowerCamelCase_						, metadata={'''help''': '''help message'''}     )
  __lowercase							:      int				=      None
  __lowercase							:      str				=      list_field(default=[]     )
  __lowercase							:      Optional[Any]				=      list_field(default=[]     )







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      List[Any]				=      list_field(default=[]     )
  __lowercase							:      List[Any]				=      list_field(default=[1, 2, 3]     )
  __lowercase							:      Union[str, Any]				=      list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']     )
  __lowercase							:      Dict				=      list_field(default=[0.1, 0.2, 0.3]     )







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      str				=      field()
  __lowercase							:      List[str]				=      field()
  __lowercase							:      int				=      field()




  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  Dict							      =					BasicEnum(self.required_enum      )







@dataclass
class        lowerCAmelCase_:
  '''simple docstring'''




  __lowercase							:      Dict				=      4_2
  __lowercase							:      Optional[Any]				=      field()
  __lowercase							:      Optional[Any]				=      None
  __lowercase							:      Union[str, Any]				=      field(default='''toto'''						, metadata={'''help''': '''help message'''}     )
  __lowercase							:      Dict				=      list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']     )


if is_python_no_less_than_3_10:






 @dataclass
 class        lowerCAmelCase_:
   '''simple docstring'''




   __lowercase							:      List[Any]				=      False
   __lowercase							:      List[Any]				=      True
   __lowercase							:      int				=      None







 @dataclass
 class        lowerCAmelCase_:
   '''simple docstring'''




   __lowercase							:      Optional[Any]				=      None
   __lowercase							:      List[str]				=      field(default=lowerCamelCase_						, metadata={'''help''': '''help message'''}     )
   __lowercase							:      Optional[int]				=      None
   __lowercase							:      List[Any]				=      list_field(default=[]     )
   __lowercase							:      Dict				=      list_field(default=[]     )






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




  def 							UpperCAmelCase_	(    self  ,__UpperCAmelCase  ,__UpperCAmelCase      )    ->		Any:
      self.assertEqual(len(a._actions      )  ,len(b._actions      )      )
      for x, y in zip(a._actions  ,b._actions      ):
          lowerCAmelCase__ :  int							      =					{k: v for k, v in vars(_lowercase      ).items() if k != """container"""}
          lowerCAmelCase__ :  Tuple							      =					{k: v for k, v in vars(_lowercase      ).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"""  ,_lowercase      ) and yy.get("""choices"""  ,_lowercase      ):
              for expected_choice in yy["choices"] + xx["choices"]:
                  self.assertEqual(xx["""type"""](_lowercase      )  ,yy["""type"""](_lowercase      )      )
              del xx["type"], yy["type"]

          self.assertEqual(_lowercase  ,_lowercase      )




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  str							      =					HfArgumentParser(_lowercase      )

      lowerCAmelCase__ :  List[str]							      =					argparse.ArgumentParser()
      expected.add_argument("""--foo"""  ,type=_lowercase  ,required=_lowercase      )
      expected.add_argument("""--bar"""  ,type=_lowercase  ,required=_lowercase      )
      expected.add_argument("""--baz"""  ,type=_lowercase  ,required=_lowercase      )
      expected.add_argument("""--flag"""  ,type=_lowercase  ,default=_lowercase  ,const=_lowercase  ,nargs="""?"""      )
      self.argparsersEqual(_lowercase  ,_lowercase      )

      lowerCAmelCase__ :  Optional[Any]							      =					["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
      ((lowerCAmelCase__     )      ,        ) :  List[str]							      =					parser.parse_args_into_dataclasses(_lowercase  ,look_for_args_file=_lowercase      )
      self.assertFalse(example.flag      )




  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  int							      =					HfArgumentParser(_lowercase      )

      lowerCAmelCase__ :  List[Any]							      =					argparse.ArgumentParser()
      expected.add_argument("""--foo"""  ,default=42  ,type=_lowercase      )
      expected.add_argument("""--baz"""  ,default="""toto"""  ,type=_lowercase  ,help="""help message"""      )
      self.argparsersEqual(_lowercase  ,_lowercase      )




  def 							UpperCAmelCase_	(    self      )    ->		Optional[Any]:
      lowerCAmelCase__ :  Tuple							      =					argparse.ArgumentParser()
      expected.add_argument("""--foo"""  ,type=_lowercase  ,default=_lowercase  ,const=_lowercase  ,nargs="""?"""      )
      expected.add_argument("""--baz"""  ,type=_lowercase  ,default=_lowercase  ,const=_lowercase  ,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=_lowercase  ,dest="""baz"""      )
      expected.add_argument("""--opt"""  ,type=_lowercase  ,default=_lowercase      )

      lowerCAmelCase__ :  List[Any]							      =					[WithDefaultBoolExample]
      if is_python_no_less_than_3_10:
          dataclass_types.append(_lowercase      )

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

          lowerCAmelCase__ :  List[str]							      =					parser.parse_args([]      )
          self.assertEqual(_lowercase  ,Namespace(foo=_lowercase  ,baz=_lowercase  ,opt=_lowercase      )      )

          lowerCAmelCase__ :  int							      =					parser.parse_args(["""--foo""", """--no_baz"""]      )
          self.assertEqual(_lowercase  ,Namespace(foo=_lowercase  ,baz=_lowercase  ,opt=_lowercase      )      )

          lowerCAmelCase__ :  Union[str, Any]							      =					parser.parse_args(["""--foo""", """--baz"""]      )
          self.assertEqual(_lowercase  ,Namespace(foo=_lowercase  ,baz=_lowercase  ,opt=_lowercase      )      )

          lowerCAmelCase__ :  Dict							      =					parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]      )
          self.assertEqual(_lowercase  ,Namespace(foo=_lowercase  ,baz=_lowercase  ,opt=_lowercase      )      )

          lowerCAmelCase__ :  Dict							      =					parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]      )
          self.assertEqual(_lowercase  ,Namespace(foo=_lowercase  ,baz=_lowercase  ,opt=_lowercase      )      )




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  Any							      =					HfArgumentParser(_lowercase      )

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

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

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

      lowerCAmelCase__ :  List[Any]							      =					parser.parse_args(["""--foo""", """42"""]      )
      self.assertEqual(args.foo  ,42      )
      lowerCAmelCase__ :  Union[str, Any]							      =					parser.parse_args_into_dataclasses(["""--foo""", """42"""]      )[0]
      self.assertEqual(enum_ex.foo  ,MixedTypeEnum.fourtytwo      )




  def 							UpperCAmelCase_	(    self      )    ->		str:






      @dataclass
      class        lowerCAmelCase_:
        '''simple docstring'''




        __lowercase							:      str				=      '''toto'''







      lowerCAmelCase__ :  List[str]							      =					HfArgumentParser(_lowercase      )

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

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

      lowerCAmelCase__ :  List[str]							      =					parser.parse_args(["""--foo""", """titi"""]      )
      self.assertEqual(args.foo  ,"""titi"""      )

      lowerCAmelCase__ :  Union[str, Any]							      =					parser.parse_args(["""--foo""", """42"""]      )
      self.assertEqual(args.foo  ,42      )




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  Tuple							      =					HfArgumentParser(_lowercase      )

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

      self.argparsersEqual(_lowercase  ,_lowercase      )

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

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




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

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

      for dataclass_type in dataclass_types:
          lowerCAmelCase__ :  Dict							      =					HfArgumentParser(_lowercase      )

          self.argparsersEqual(_lowercase  ,_lowercase      )

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

          lowerCAmelCase__ :  List[Any]							      =					parser.parse_args("""--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3""".split()      )
          self.assertEqual(_lowercase  ,Namespace(foo=12  ,bar=3.1_4  ,baz="""42"""  ,ces=["""a""", """b""", """c"""]  ,des=[1, 2, 3]      )      )




  def 							UpperCAmelCase_	(    self      )    ->		List[Any]:
      lowerCAmelCase__ :  List[str]							      =					HfArgumentParser(_lowercase      )

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




  def 							UpperCAmelCase_	(    self      )    ->		Optional[Any]:
      lowerCAmelCase__ :  int							      =					HfArgumentParser(_lowercase      )

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




  def 							UpperCAmelCase_	(    self      )    ->		Any:
      lowerCAmelCase__ :  Tuple							      =					HfArgumentParser(_lowercase      )

      lowerCAmelCase__ :  Optional[int]							      =					{
          """foo""": 12,
          """bar""": 3.1_4,
          """baz""": """42""",
          """flag""": True,
      }

      lowerCAmelCase__ :  Union[str, Any]							      =					parser.parse_dict(_lowercase      )[0]
      lowerCAmelCase__ :  Optional[int]							      =					BasicExample(**_lowercase      )
      self.assertEqual(_lowercase  ,_lowercase      )




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  Optional[Any]							      =					HfArgumentParser(_lowercase      )

      lowerCAmelCase__ :  Dict							      =					{
          """foo""": 12,
          """bar""": 3.1_4,
          """baz""": """42""",
          """flag""": True,
          """extra""": 42,
      }

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




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  int							      =					HfArgumentParser(_lowercase      )

      lowerCAmelCase__ :  str							      =					{
          """foo""": 12,
          """bar""": 3.1_4,
          """baz""": """42""",
          """flag""": True,
      }
      with tempfile.TemporaryDirectory() as tmp_dir:
          lowerCAmelCase__ :  Optional[int]							      =					os.path.join(_lowercase  ,"""temp_json"""      )
          os.mkdir(_lowercase      )
          with open(temp_local_path + """.json"""  ,"""w+"""      ) as f:
              json.dump(_lowercase  ,_lowercase      )
          lowerCAmelCase__ :  str							      =					parser.parse_yaml_file(Path(temp_local_path + """.json"""      )      )[0]

      lowerCAmelCase__ :  int							      =					BasicExample(**_lowercase      )
      self.assertEqual(_lowercase  ,_lowercase      )




  def 							UpperCAmelCase_	(    self      )    ->		Optional[Any]:
      lowerCAmelCase__ :  List[str]							      =					HfArgumentParser(_lowercase      )

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






  def 							UpperCAmelCase_	(    self      )    ->		str:
      lowerCAmelCase__ :  List[str]							      =					HfArgumentParser(_lowercase      )
      self.assertIsNotNone(_lowercase      )



def 	__SCREAMING_SNAKE_CASE  (					__UpperCamelCase    :       int ,     __UpperCamelCase    :       int	)							->					str:







  """simple docstring"""





  if a < 0 or b < 0:
    raise ValueError("""the value of both inputs must be positive"""	)

  SCREAMING_SNAKE_CASE__										=      str(bin(__UpperCamelCase	)	)[2:]  # remove the leading "0b"
  SCREAMING_SNAKE_CASE__										=      str(bin(__UpperCamelCase	)	)[2:]  # remove the leading "0b"

  SCREAMING_SNAKE_CASE__										=      max(len(__UpperCamelCase	) ,     len(__UpperCamelCase	)	)

  return "0b" + "".join(
      str(int(char_a != char_b	)	)
      for char_a, char_b in zip(a_binary.zfill(__UpperCamelCase	) ,     b_binary.zfill(__UpperCamelCase	)	)	)


if __name__ == "__main__":
   import doctest

   doctest.testmod()
