



'''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, 10)

def        a_     (							_lowerCAmelCase=None       ,_lowerCAmelCase=None       )      ->      List[str]:
  return field(default_factory=lambda: default       ,metadata=_lowerCAmelCase       )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=42
  a_												=42
  a_												=42
  a_												=42






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=42
  a_												=field(default="""toto"""   ,   metadata={"""help""": """help message"""}     )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=False
  a_												=True
  a_												=None






class 					lowerCamelCase_    (				SCREAMING_SNAKE_CASE_     ):
  """simple docstring"""




  a_												="""titi"""
  a_												="""toto"""






class 					lowerCamelCase_    (				SCREAMING_SNAKE_CASE_     ):
  """simple docstring"""




  a_												="""titi"""
  a_												="""toto"""
  a_												=42






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												="toto"




  def 						_lowercase     ( self      :	List[Any]   )					->					Dict:
    __lowerCamelCase       :       List[str]           = BasicEnum(self.foo   )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												="toto"




  def 						_lowercase     ( self      :	Any   )					->					Optional[Any]:
    __lowerCamelCase       :       Optional[Any]           = MixedTypeEnum(self.foo   )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=None
  a_												=field(default=SCREAMING_SNAKE_CASE_   ,   metadata={"""help""": """help message"""}     )
  a_												=None
  a_												=list_field(default=[]     )
  a_												=list_field(default=[]     )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=list_field(default=[]     )
  a_												=list_field(default=[1, 2, 3]     )
  a_												=list_field(default=["""Hallo""", """Bonjour""", """Hello"""]     )
  a_												=list_field(default=[0.1, 0.2, 0.3]     )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=field()
  a_												=field()
  a_												=field()




  def 						_lowercase     ( self      :	Optional[Any]   )					->					int:
    __lowerCamelCase       :       int           = BasicEnum(self.required_enum   )






@dataclass
class 					lowerCamelCase_    :
  """simple docstring"""




  a_												=42
  a_												=field()
  a_												=None
  a_												=field(default="""toto"""   ,   metadata={"""help""": """help message"""}     )
  a_												=list_field(default=["""Hallo""", """Bonjour""", """Hello"""]     )


if is_python_no_less_than_3_10:






   @dataclass
   class 					lowerCamelCase_    :
     """simple docstring"""




     a_												=False
     a_												=True
     a_												=None






   @dataclass
   class 					lowerCamelCase_    :
     """simple docstring"""




     a_												=None
     a_												=field(default=SCREAMING_SNAKE_CASE_   ,   metadata={"""help""": """help message"""}     )
     a_												=None
     a_												=list_field(default=[]     )
     a_												=list_field(default=[]     )






class 					lowerCamelCase_    (				unittest.TestCase     ):
  """simple docstring"""




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

      self.assertEqual(_a			,	_a   )




  def 						_lowercase     ( self      :	Optional[int]   )					->					Tuple:
    __lowerCamelCase       :       Optional[int]           = HfArgumentParser(_a   )

    __lowerCamelCase       :       Union[str, Any]           = argparse.ArgumentParser()
    expected.add_argument('--foo'			,	type=_a			,	required=_a   )
    expected.add_argument('--bar'			,	type=_a			,	required=_a   )
    expected.add_argument('--baz'			,	type=_a			,	required=_a   )
    expected.add_argument('--flag'			,	type=_a			,	default=_a			,	const=_a			,	nargs='?'   )
    self.argparsersEqual(_a			,	_a   )

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




  def 						_lowercase     ( self      :	Tuple   )					->					str:
    __lowerCamelCase       :       Optional[Any]           = HfArgumentParser(_a   )

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




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

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

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

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

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

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

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

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




  def 						_lowercase     ( self      :	Dict   )					->					Dict:
    __lowerCamelCase       :       int           = HfArgumentParser(_a   )

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

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

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

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




  def 						_lowercase     ( self      :	List[str]   )					->					int:






    @dataclass
    class 					lowerCamelCase_    :
      """simple docstring"""




      a_												="toto"




    __lowerCamelCase       :       int           = HfArgumentParser(_a   )

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

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

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

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




  def 						_lowercase     ( self      :	List[Any]   )					->					Union[str, Any]:
    __lowerCamelCase       :       str           = HfArgumentParser(_a   )

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

    self.argparsersEqual(_a			,	_a   )

    __lowerCamelCase       :       List[Any]           = parser.parse_args([]   )
    self.assertEqual(
        _a			,	Namespace(foo_int=[]			,	bar_int=[1, 2, 3]			,	foo_str=['Hallo', 'Bonjour', 'Hello']			,	foo_float=[0.1, 0.2, 0.3]   )			,	)

    __lowerCamelCase       :       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(_a			,	Namespace(foo_int=[1]			,	bar_int=[2, 3]			,	foo_str=['a', 'b', 'c']			,	foo_float=[0.1, 0.7]   )   )




  def 						_lowercase     ( self      :	List[Any]   )					->					List[Any]:
    __lowerCamelCase       :       List[str]           = argparse.ArgumentParser()
    expected.add_argument('--foo'			,	default=_a			,	type=_a   )
    expected.add_argument('--bar'			,	default=_a			,	type=_a			,	help='help message'   )
    expected.add_argument('--baz'			,	default=_a			,	type=_a   )
    expected.add_argument('--ces'			,	nargs='+'			,	default=[]			,	type=_a   )
    expected.add_argument('--des'			,	nargs='+'			,	default=[]			,	type=_a   )

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

    for dataclass_type in dataclass_types:
      __lowerCamelCase       :       Optional[int]           = HfArgumentParser(_a   )

      self.argparsersEqual(_a			,	_a   )

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

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




  def 						_lowercase     ( self      :	List[str]   )					->					Optional[int]:
    __lowerCamelCase       :       Dict           = HfArgumentParser(_a   )

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




  def 						_lowercase     ( self      :	Optional[int]   )					->					Optional[int]:
    __lowerCamelCase       :       Optional[int]           = HfArgumentParser(_a   )

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




  def 						_lowercase     ( self      :	Tuple   )					->					Any:
    __lowerCamelCase       :       List[str]           = HfArgumentParser(_a   )

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

    __lowerCamelCase       :       Union[str, Any]           = parser.parse_dict(_a   )[0]
    __lowerCamelCase       :       Any           = BasicExample(**_a   )
    self.assertEqual(_a			,	_a   )




  def 						_lowercase     ( self      :	Union[str, Any]   )					->					str:
    __lowerCamelCase       :       List[str]           = HfArgumentParser(_a   )

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

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




  def 						_lowercase     ( self      :	List[str]   )					->					List[Any]:
    __lowerCamelCase       :       Tuple           = HfArgumentParser(_a   )

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

    __lowerCamelCase       :       Any           = BasicExample(**_a   )
    self.assertEqual(_a			,	_a   )




  def 						_lowercase     ( self      :	Dict   )					->					Tuple:
    __lowerCamelCase       :       int           = HfArgumentParser(_a   )

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




  def 						_lowercase     ( self      :	str   )					->					Dict:
    __lowerCamelCase       :       Any           = HfArgumentParser(_a   )
    self.assertIsNotNone(_a   )











'''simple docstring'''





def        a_     (							_lowerCAmelCase       )      ->      str:
  if not all(char in '01' for char in bin_string       ):
    raise ValueError('Non-binary value was passed to the function'       )
  if not bin_string:
    raise ValueError('Empty string was passed to the function'       )
  __lowerCamelCase       :       int           = ''
  while len(_lowerCAmelCase       ) % 3 != 0:
    __lowerCamelCase       :       str           = '0' + bin_string
  __lowerCamelCase       :       Union[str, Any]           = [
      bin_string[index : index + 3]
      for index in range(len(_lowerCAmelCase       )       )
      if index % 3 == 0
  ]
  for bin_group in bin_string_in_3_list:
    __lowerCamelCase       :       Tuple           = 0
    for index, val in enumerate(_lowerCAmelCase       ):
      oct_val += int(2 ** (2 - index) * int(_lowerCAmelCase       )       )
    oct_string += str(_lowerCAmelCase       )
  return oct_string


if __name__ == "__main__":
   from doctest import testmod

   testmod()






