



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


def 	UpperCAmelCase__      (      UpperCAmelCase__ :Dict=None ,					UpperCAmelCase__ :Any=None					):






 '''simple docstring'''

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



@dataclass
class 		_lowercase		:
   _UpperCAmelCase     	=			42
   _UpperCAmelCase     	=			42
   _UpperCAmelCase     	=			42
   _UpperCAmelCase     	=			42



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



@dataclass
class 		_lowercase		:
   _UpperCAmelCase     	=			False
   _UpperCAmelCase     	=			True
   _UpperCAmelCase     	=			None



class 		_lowercase		(       _UpperCAmelCase	):
   _UpperCAmelCase     	=			"""titi"""
   _UpperCAmelCase     	=			"""toto"""



class 		_lowercase		(       _UpperCAmelCase	):
   _UpperCAmelCase     	=			"""titi"""
   _UpperCAmelCase     	=			"""toto"""
   _UpperCAmelCase     	=			42



@dataclass
class 		_lowercase		:
   _UpperCAmelCase     	=			"toto"

   def 		A							(      self			:       Optional[int]							)       ->				Dict:


    """simple docstring"""






    a						=		BasicEnum(self.foo							)



@dataclass
class 		_lowercase		:
   _UpperCAmelCase     	=			"toto"

   def 		A							(      self			:       Optional[Any]							)       ->				Optional[Any]:


    """simple docstring"""






    a						=		MixedTypeEnum(self.foo							)



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



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



@dataclass
class 		_lowercase		:
   _UpperCAmelCase     	=			field()
   _UpperCAmelCase     	=			field()
   _UpperCAmelCase     	=			field()

   def 		A							(      self			:       Any							)       ->				Optional[Any]:


    """simple docstring"""






    a						=		BasicEnum(self.required_enum							)



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


if is_python_no_less_than_3_10:



     @dataclass
     class 		_lowercase		:
        _UpperCAmelCase     	=			False
        _UpperCAmelCase     	=			True
        _UpperCAmelCase     	=			None



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




class 		_lowercase		(       unittest.TestCase	):

   def 		A							(      self			:       str							,   __lowerCAmelCase			:       Optional[Any]							,   __lowerCAmelCase			:       Tuple							)       ->				Dict:


    """simple docstring"""






    self.assertEqual(len(a._actions							)							,   len(b._actions							)							)
    for x, y in zip(a._actions							,   b._actions							):
     a						=		{k: v for k, v in vars(lowercase__							).items() if k != """container"""}
     a						=		{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 		A							(      self			:       Optional[Any]							)       ->				Tuple:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		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__							)

    a						=		["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
    (a			)						=		parser.parse_args_into_dataclasses(lowercase__							,   look_for_args_file=lowercase__							)
    self.assertFalse(example.flag							)

   def 		A							(      self			:       Any							)       ->				Optional[Any]:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		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 		A							(      self			:       Tuple							)       ->				int:


    """simple docstring"""






    a						=		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__							)

    a						=		[WithDefaultBoolExample]
    if is_python_no_less_than_3_10:
     dataclass_types.append(lowercase__							)

    for dataclass_type in dataclass_types:
     a						=		HfArgumentParser(lowercase__							)
     self.argparsersEqual(lowercase__							,   lowercase__							)

     a						=		parser.parse_args([]							)
     self.assertEqual(lowercase__							,   Namespace(foo=lowercase__							,   baz=lowercase__							,   opt=lowercase__							)							)

     a						=		parser.parse_args(["--foo", "--no_baz"]							)
     self.assertEqual(lowercase__							,   Namespace(foo=lowercase__							,   baz=lowercase__							,   opt=lowercase__							)							)

     a						=		parser.parse_args(["--foo", "--baz"]							)
     self.assertEqual(lowercase__							,   Namespace(foo=lowercase__							,   baz=lowercase__							,   opt=lowercase__							)							)

     a						=		parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]							)
     self.assertEqual(lowercase__							,   Namespace(foo=lowercase__							,   baz=lowercase__							,   opt=lowercase__							)							)

     a						=		parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]							)
     self.assertEqual(lowercase__							,   Namespace(foo=lowercase__							,   baz=lowercase__							,   opt=lowercase__							)							)

   def 		A							(      self			:       Tuple							)       ->				List[Any]:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		argparse.ArgumentParser()
    expected.add_argument(
        "--foo"							,   default="toto"							,   choices=["titi", "toto", 42]							,   type=make_choice_type_function(["titi", "toto", 42]							)							,   )
    self.argparsersEqual(lowercase__							,   lowercase__							)

    a						=		parser.parse_args([]							)
    self.assertEqual(args.foo							,   "toto"							)
    a						=		parser.parse_args_into_dataclasses([]							)[0]
    self.assertEqual(enum_ex.foo							,   MixedTypeEnum.toto							)

    a						=		parser.parse_args(["--foo", "titi"]							)
    self.assertEqual(args.foo							,   "titi"							)
    a						=		parser.parse_args_into_dataclasses(["--foo", "titi"]							)[0]
    self.assertEqual(enum_ex.foo							,   MixedTypeEnum.titi							)

    a						=		parser.parse_args(["--foo", "42"]							)
    self.assertEqual(args.foo							,   42							)
    a						=		parser.parse_args_into_dataclasses(["--foo", "42"]							)[0]
    self.assertEqual(enum_ex.foo							,   MixedTypeEnum.fourtytwo							)

   def 		A							(      self			:       Any							)       ->				Union[str, Any]:


    """simple docstring"""






    @dataclass
    class 		_lowercase		:
       _UpperCAmelCase     	=			"toto"

    a						=		HfArgumentParser(lowercase__							)

    a						=		argparse.ArgumentParser()
    expected.add_argument(
        "--foo"							,   default="toto"							,   choices=("titi", "toto", 42)							,   type=make_choice_type_function(["titi", "toto", 42]							)							,   )
    self.argparsersEqual(lowercase__							,   lowercase__							)

    a						=		parser.parse_args([]							)
    self.assertEqual(args.foo							,   "toto"							)

    a						=		parser.parse_args(["--foo", "titi"]							)
    self.assertEqual(args.foo							,   "titi"							)

    a						=		parser.parse_args(["--foo", "42"]							)
    self.assertEqual(args.foo							,   42							)

   def 		A							(      self			:       List[str]							)       ->				Tuple:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		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__							)

    a						=		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]							)							,   )

    a						=		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 		A							(      self			:       Optional[Any]							)       ->				Any:


    """simple docstring"""






    a						=		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__							)

    a						=		[OptionalExample]
    if is_python_no_less_than_3_10:
     dataclass_types.append(lowercase__							)

    for dataclass_type in dataclass_types:
     a						=		HfArgumentParser(lowercase__							)

     self.argparsersEqual(lowercase__							,   lowercase__							)

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

     a						=		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 		A							(      self			:       int							)       ->				List[str]:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		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 		A							(      self			:       Optional[Any]							)       ->				Dict:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		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 		A							(      self			:       Optional[int]							)       ->				Optional[Any]:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

    a						=		{
        """foo""": 12,
        """bar""": 3.1_4,
        """baz""": """42""",
        """flag""": True,
    }

    a						=		parser.parse_dict(lowercase__							)[0]
    a						=		BasicExample(**lowercase__							)
    self.assertEqual(lowercase__							,   lowercase__							)

   def 		A							(      self			:       Dict							)       ->				Optional[int]:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

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

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

   def 		A							(      self			:       Union[str, Any]							)       ->				Optional[int]:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

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

    a						=		BasicExample(**lowercase__							)
    self.assertEqual(lowercase__							,   lowercase__							)

   def 		A							(      self			:       Union[str, Any]							)       ->				Tuple:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)

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




   def 		A							(      self			:       Tuple							)       ->				str:


    """simple docstring"""






    a						=		HfArgumentParser(lowercase__							)
    self.assertIsNotNone(lowercase__							)






def 	UpperCAmelCase__      (      UpperCAmelCase__ :int ,					UpperCAmelCase__ :int					):






 '''simple docstring'''

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

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

 a						=		max(len(UpperCAmelCase__					) ,					len(UpperCAmelCase__					)					)

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


if __name__ == "__main__":
     import doctest

     doctest.testmod()

