




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



def       UpperCAmelCase__  (     lowerCamelCase=None,			lowerCamelCase=None   ):
  return field(default_factory=lambda: default,			metadata=lowerCamelCase   )




@dataclass
class    __lowerCAmelCase       :
       _a 					=						42
       _a 					=						42
       _a 					=						42
       _a 					=						42







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







@dataclass
class    __lowerCAmelCase       :
       _a 					=						False
       _a 					=						True
       _a 					=						None







class    __lowerCAmelCase       (							lowerCAmelCase):
       _a 					=						'''titi'''
       _a 					=						'''toto'''







class    __lowerCAmelCase       (							lowerCAmelCase):
       _a 					=						'''titi'''
       _a 					=						'''toto'''
       _a 					=						42







@dataclass
class    __lowerCAmelCase       :
       _a 					=						"toto"






       def 					SCREAMING_SNAKE_CASE    (   self:					Optional[Any]				):
         lowercase    :Optional[int]      	=						BasicEnum(self.foo				)







@dataclass
class    __lowerCAmelCase       :
       _a 					=						"toto"






       def 					SCREAMING_SNAKE_CASE    (   self:					Tuple				):
         lowercase    :Tuple      	=						MixedTypeEnum(self.foo				)







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







@dataclass
class    __lowerCAmelCase       :
       _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       :
       _a 					=						field()
       _a 					=						field()
       _a 					=						field()






       def 					SCREAMING_SNAKE_CASE    (   self:					Any				):
         lowercase    :List[Any]      	=						BasicEnum(self.required_enum				)







@dataclass
class    __lowerCAmelCase       :
       _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       :
            _a 					=						False
            _a 					=						True
            _a 					=						None







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







class    __lowerCAmelCase       (							unittest.TestCase):






       def 					SCREAMING_SNAKE_CASE    (   self:					Any       ,					_lowerCAmelCase:					argparse.ArgumentParser       ,					_lowerCAmelCase:					argparse.ArgumentParser				):
         self.assertEqual(len(a._actions				)       ,					len(b._actions				)				)
         for x, y in zip(a._actions       ,					b._actions				):
           lowercase    :Optional[Any]      	=						{k: v for k, v in vars(_lowerCAmelCase				).items() if k != "container"}
           lowercase    :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 					SCREAMING_SNAKE_CASE    (   self:					int				):
         lowercase    :Optional[int]      	=						HfArgumentParser(_lowerCAmelCase				)

         lowercase    :Optional[int]      	=						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				)

         lowercase    :Dict      	=						["--foo", "1", "--baz", "quux", "--bar", "0.5"]
         ((lowercase)	,    )    :int      	=						parser.parse_args_into_dataclasses(_lowerCAmelCase       ,					look_for_args_file=_lowerCAmelCase				)
         self.assertFalse(example.flag				)






       def 					SCREAMING_SNAKE_CASE    (   self:					List[str]				):
         lowercase    :Tuple      	=						HfArgumentParser(_lowerCAmelCase				)

         lowercase    :Tuple      	=						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 					SCREAMING_SNAKE_CASE    (   self:					Optional[int]				):
         lowercase    :Union[str, Any]      	=						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				)

         lowercase    :str      	=						[WithDefaultBoolExample]
         if is_python_no_less_than_3_10:
           dataclass_types.append(_lowerCAmelCase				)

         for dataclass_type in dataclass_types:
           lowercase    :Union[str, Any]      	=						HfArgumentParser(_lowerCAmelCase				)
           self.argparsersEqual(_lowerCAmelCase       ,					_lowerCAmelCase				)

           lowercase    :Tuple      	=						parser.parse_args([]				)
           self.assertEqual(_lowerCAmelCase       ,					Namespace(foo=_lowerCAmelCase       ,					baz=_lowerCAmelCase       ,					opt=_lowerCAmelCase				)				)

           lowercase    :Optional[Any]      	=						parser.parse_args(["--foo", "--no_baz"]				)
           self.assertEqual(_lowerCAmelCase       ,					Namespace(foo=_lowerCAmelCase       ,					baz=_lowerCAmelCase       ,					opt=_lowerCAmelCase				)				)

           lowercase    :int      	=						parser.parse_args(["--foo", "--baz"]				)
           self.assertEqual(_lowerCAmelCase       ,					Namespace(foo=_lowerCAmelCase       ,					baz=_lowerCAmelCase       ,					opt=_lowerCAmelCase				)				)

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

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






       def 					SCREAMING_SNAKE_CASE    (   self:					int				):
         lowercase    :int      	=						HfArgumentParser(_lowerCAmelCase				)

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

         lowercase    :Dict      	=						parser.parse_args([]				)
         self.assertEqual(args.foo       ,					"toto"				)
         lowercase    :Optional[Any]      	=						parser.parse_args_into_dataclasses([]				)[0]
         self.assertEqual(enum_ex.foo       ,					MixedTypeEnum.toto				)

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

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






       def 					SCREAMING_SNAKE_CASE    (   self:					Tuple				):




         @dataclass
         class    __lowerCAmelCase       :
                _a 					=						"toto"







         lowercase    :List[Any]      	=						HfArgumentParser(_lowerCAmelCase				)

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

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

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

         lowercase    :Optional[int]      	=						parser.parse_args(["--foo", "42"]				)
         self.assertEqual(args.foo       ,					42				)






       def 					SCREAMING_SNAKE_CASE    (   self:					List[str]				):
         lowercase    :Tuple      	=						HfArgumentParser(_lowerCAmelCase				)

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

         lowercase    :List[Any]      	=						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]				)       ,					)

         lowercase    :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 					SCREAMING_SNAKE_CASE    (   self:					str				):
         lowercase    :Optional[int]      	=						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				)

         lowercase    :Any      	=						[OptionalExample]
         if is_python_no_less_than_3_10:
           dataclass_types.append(_lowerCAmelCase				)

         for dataclass_type in dataclass_types:
           lowercase    :Optional[int]      	=						HfArgumentParser(_lowerCAmelCase				)

           self.argparsersEqual(_lowerCAmelCase       ,					_lowerCAmelCase				)

           lowercase    :Optional[Any]      	=						parser.parse_args([]				)
           self.assertEqual(_lowerCAmelCase       ,					Namespace(foo=_lowerCAmelCase       ,					bar=_lowerCAmelCase       ,					baz=_lowerCAmelCase       ,					ces=[]       ,					des=[]				)				)

           lowercase    :Tuple      	=						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 					SCREAMING_SNAKE_CASE    (   self:					Tuple				):
         lowercase    :Optional[int]      	=						HfArgumentParser(_lowerCAmelCase				)

         lowercase    :int      	=						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 					SCREAMING_SNAKE_CASE    (   self:					Union[str, Any]				):
         lowercase    :Optional[int]      	=						HfArgumentParser(_lowerCAmelCase				)

         lowercase    :Optional[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 					SCREAMING_SNAKE_CASE    (   self:					Optional[int]				):
         lowercase    :Optional[int]      	=						HfArgumentParser(_lowerCAmelCase				)

         lowercase    :Any      	=						{
             "foo": 12,
             "bar": 3.14,
             "baz": "42",
             "flag": True,
         }

         lowercase    :Optional[int]      	=						parser.parse_dict(_lowerCAmelCase				)[0]
         lowercase    :Any      	=						BasicExample(**_lowerCAmelCase				)
         self.assertEqual(_lowerCAmelCase       ,					_lowerCAmelCase				)






       def 					SCREAMING_SNAKE_CASE    (   self:					Any				):
         lowercase    :str      	=						HfArgumentParser(_lowerCAmelCase				)

         lowercase    :str      	=						{
             "foo": 12,
             "bar": 3.14,
             "baz": "42",
             "flag": True,
             "extra": 42,
         }

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






       def 					SCREAMING_SNAKE_CASE    (   self:					int				):
         lowercase    :Union[str, Any]      	=						HfArgumentParser(_lowerCAmelCase				)

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

         lowercase    :Union[str, Any]      	=						BasicExample(**_lowerCAmelCase				)
         self.assertEqual(_lowerCAmelCase       ,					_lowerCAmelCase				)






       def 					SCREAMING_SNAKE_CASE    (   self:					Tuple				):
         lowercase    :Optional[Any]      	=						HfArgumentParser(_lowerCAmelCase				)

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






       def 					SCREAMING_SNAKE_CASE    (   self:					Tuple				):
         lowercase    :List[Any]      	=						HfArgumentParser(_lowerCAmelCase				)
         self.assertIsNotNone(_lowerCAmelCase				)









import string



def       UpperCAmelCase__  (     lowerCamelCase   ):
  lowercase    :Optional[int]      	=						""
  for i in sequence:
    lowercase    :Optional[Any]      	=						ord(lowerCamelCase   )
    if 65 <= extract <= 90:
      output += chr(155 - extract   )
    elif 97 <= extract <= 122:
      output += chr(219 - extract   )
    else:
      output += i
  return output



def       UpperCAmelCase__  (     lowerCamelCase   ):
  lowercase    :Union[str, Any]      	=						string.ascii_letters
  lowercase    :Dict      	=						string.ascii_lowercase[::-1] + string.ascii_uppercase[::-1]
  return "".join(
      letters_reversed[letters.index(lowerCamelCase   )] if c in letters else c for c in sequence   )



def       UpperCAmelCase__  (     ):
  from timeit import timeit

  print("Running performance benchmarks..."   )
  lowercase    :Dict      	=						"from string import printable ; from __main__ import atbash, atbash_slow"
  print(F"> atbash_slow(): {timeit('atbash_slow(printable)',			setup=lowerCamelCase   )} seconds"   )
  print(F">      atbash(): {timeit('atbash(printable)',			setup=lowerCamelCase   )} seconds"   )


if __name__ == "__main__":
     for example in ("ABCDEFGH", "123GGjj", "testStringtest", "with space"):
          print(f'''{example} encrypted in atbash: {atbash(example)}''')
     benchmark()



