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





def 				lowerCAmelCase__      (     _UpperCamelCase    :			int=None	,     _UpperCamelCase    :			int=None   )   ->			Optional[int]:





      """simple docstring"""






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



@dataclass
class 					lowerCAmelCase_      :



    """simple docstring"""
    _lowerCAmelCase       :      int
    _lowerCAmelCase       :      float
    _lowerCAmelCase       :      str
    _lowerCAmelCase       :      bool





@dataclass
class 					lowerCAmelCase_      :



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





@dataclass
class 					lowerCAmelCase_      :



    """simple docstring"""
    _lowerCAmelCase       :      bool     					=  False
    _lowerCAmelCase       :      bool     					=  True
    _lowerCAmelCase       :      Optional[bool]     					=  None





class 					lowerCAmelCase_      (     SCREAMING_SNAKE_CASE__   ):



    """simple docstring"""
    _lowerCAmelCase       :      Tuple     					=  'titi'
    _lowerCAmelCase       :      List[str]     					=  'toto'





class 					lowerCAmelCase_      (     SCREAMING_SNAKE_CASE__   ):



    """simple docstring"""
    _lowerCAmelCase       :      Tuple     					=  'titi'
    _lowerCAmelCase       :      List[Any]     					=  'toto'
    _lowerCAmelCase       :      Union[str, Any]     					=  42





@dataclass
class 					lowerCAmelCase_      :



    """simple docstring"""
    _lowerCAmelCase       :      BasicEnum     					=  "toto"

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     BasicEnum(self.foo      )





@dataclass
class 					lowerCAmelCase_      :



    """simple docstring"""
    _lowerCAmelCase       :      MixedTypeEnum     					=  "toto"

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     MixedTypeEnum(self.foo      )





@dataclass
class 					lowerCAmelCase_      :



    """simple docstring"""
    _lowerCAmelCase       :      Optional[int]     					=  None
    _lowerCAmelCase       :      Optional[float]     					=  field(default=SCREAMING_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 					lowerCAmelCase_      :



    """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 					lowerCAmelCase_      :



    """simple docstring"""
    _lowerCAmelCase       :      List[int]     					=  field()
    _lowerCAmelCase       :      str     					=  field()
    _lowerCAmelCase       :      BasicEnum     					=  field()

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     BasicEnum(self.required_enum      )





@dataclass
class 					lowerCAmelCase_      :



    """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 					lowerCAmelCase_      :



         """simple docstring"""
         _lowerCAmelCase       :      bool     					=  False
         _lowerCAmelCase       :      bool     					=  True
         _lowerCAmelCase       :      bool | None     					=  None





     @dataclass
     class 					lowerCAmelCase_      :



         """simple docstring"""
         _lowerCAmelCase       :      int | None     					=  None
         _lowerCAmelCase       :      float | None     					=  field(default=SCREAMING_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 					lowerCAmelCase_      (     unittest.TestCase   ):



    """simple docstring"""

    def 						snake_case	(			self						,      lowerCAmelCase						,      lowerCAmelCase      ):






          """simple docstring"""

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

                self.assertEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument('--foo'						,      type=_SCREAMING_SNAKE_CASE						,      required=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--bar'						,      type=_SCREAMING_SNAKE_CASE						,      required=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--baz'						,      type=_SCREAMING_SNAKE_CASE						,      required=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--flag'						,      type=_SCREAMING_SNAKE_CASE						,      default=_SCREAMING_SNAKE_CASE						,      const=_SCREAMING_SNAKE_CASE						,      nargs='?'      )
          self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument('--foo'						,      default=42						,      type=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--baz'						,      default='toto'						,      type=_SCREAMING_SNAKE_CASE						,      help='help message'      )
          self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument('--foo'						,      type=_SCREAMING_SNAKE_CASE						,      default=_SCREAMING_SNAKE_CASE						,      const=_SCREAMING_SNAKE_CASE						,      nargs='?'      )
          expected.add_argument('--baz'						,      type=_SCREAMING_SNAKE_CASE						,      default=_SCREAMING_SNAKE_CASE						,      const=_SCREAMING_SNAKE_CASE						,      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=_SCREAMING_SNAKE_CASE						,      dest='baz'      )
          expected.add_argument('--opt'						,      type=_SCREAMING_SNAKE_CASE						,      default=_SCREAMING_SNAKE_CASE      )

          snake_case        =     [WithDefaultBoolExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(_SCREAMING_SNAKE_CASE      )

          for dataclass_type in dataclass_types:
                snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )
                self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

                snake_case        =     parser.parse_args([]      )
                self.assertEqual(_SCREAMING_SNAKE_CASE						,      Namespace(foo=_SCREAMING_SNAKE_CASE						,      baz=_SCREAMING_SNAKE_CASE						,      opt=_SCREAMING_SNAKE_CASE      )      )

                snake_case        =     parser.parse_args(['--foo', '--no_baz']      )
                self.assertEqual(_SCREAMING_SNAKE_CASE						,      Namespace(foo=_SCREAMING_SNAKE_CASE						,      baz=_SCREAMING_SNAKE_CASE						,      opt=_SCREAMING_SNAKE_CASE      )      )

                snake_case        =     parser.parse_args(['--foo', '--baz']      )
                self.assertEqual(_SCREAMING_SNAKE_CASE						,      Namespace(foo=_SCREAMING_SNAKE_CASE						,      baz=_SCREAMING_SNAKE_CASE						,      opt=_SCREAMING_SNAKE_CASE      )      )

                snake_case        =     parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']      )
                self.assertEqual(_SCREAMING_SNAKE_CASE						,      Namespace(foo=_SCREAMING_SNAKE_CASE						,      baz=_SCREAMING_SNAKE_CASE						,      opt=_SCREAMING_SNAKE_CASE      )      )

                snake_case        =     parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']      )
                self.assertEqual(_SCREAMING_SNAKE_CASE						,      Namespace(foo=_SCREAMING_SNAKE_CASE						,      baz=_SCREAMING_SNAKE_CASE						,      opt=_SCREAMING_SNAKE_CASE      )      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument(
              '--foo'						,      default='toto'						,      choices=['titi', 'toto', 42]						,      type=make_choice_type_function(['titi', 'toto', 42]      )						,      )
          self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

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

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

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          @dataclass
          class 					lowerCAmelCase_      :



              """simple docstring"""
              _lowerCAmelCase       :      Literal["titi", "toto", 42]     					=  "toto"





          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument(
              '--foo'						,      default='toto'						,      choices=('titi', 'toto', 42)						,      type=make_choice_type_function(['titi', 'toto', 42]      )						,      )
          self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

          snake_case        =     parser.parse_args([]      )
          self.assertEqual(args.foo						,      'toto'      )

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

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

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

          self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

          snake_case        =     parser.parse_args([]      )
          self.assertEqual(
              _SCREAMING_SNAKE_CASE						,      Namespace(foo_int=[]						,      bar_int=[1, 2, 3]						,      foo_str=['Hallo', 'Bonjour', 'Hello']						,      foo_float=[0.1, 0.2, 0.3]      )						,      )

          snake_case        =     parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split()      )
          self.assertEqual(_SCREAMING_SNAKE_CASE						,      Namespace(foo_int=[1]						,      bar_int=[2, 3]						,      foo_str=['a', 'b', 'c']						,      foo_float=[0.1, 0.7]      )      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument('--foo'						,      default=_SCREAMING_SNAKE_CASE						,      type=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--bar'						,      default=_SCREAMING_SNAKE_CASE						,      type=_SCREAMING_SNAKE_CASE						,      help='help message'      )
          expected.add_argument('--baz'						,      default=_SCREAMING_SNAKE_CASE						,      type=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--ces'						,      nargs='+'						,      default=[]						,      type=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--des'						,      nargs='+'						,      default=[]						,      type=_SCREAMING_SNAKE_CASE      )

          snake_case        =     [OptionalExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(_SCREAMING_SNAKE_CASE      )

          for dataclass_type in dataclass_types:
                snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

                self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

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

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

          snake_case        =     argparse.ArgumentParser()
          expected.add_argument('--required_list'						,      nargs='+'						,      type=_SCREAMING_SNAKE_CASE						,      required=_SCREAMING_SNAKE_CASE      )
          expected.add_argument('--required_str'						,      type=_SCREAMING_SNAKE_CASE						,      required=_SCREAMING_SNAKE_CASE      )
          expected.add_argument(
              '--required_enum'						,      type=make_choice_type_function(['titi', 'toto']      )						,      choices=['titi', 'toto']						,      required=_SCREAMING_SNAKE_CASE						,      )
          self.argparsersEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

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

          snake_case        =     parser.parse_dict(_SCREAMING_SNAKE_CASE      )[0]
          snake_case        =     BasicExample(**_SCREAMING_SNAKE_CASE      )
          self.assertEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

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

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

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

          snake_case        =     BasicExample(**_SCREAMING_SNAKE_CASE      )
          self.assertEqual(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE      )

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )

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

    def 						snake_case	(			self      ):






          """simple docstring"""

          snake_case        =     HfArgumentParser(_SCREAMING_SNAKE_CASE      )
          self.assertIsNotNone(_SCREAMING_SNAKE_CASE      )



"""simple docstring"""
import cmath
import math





def 				lowerCAmelCase__      (     _UpperCamelCase    :			float	,     _UpperCamelCase    :			float	,     _UpperCamelCase    :			float	,     _UpperCamelCase    :			float   )   ->			complex:





						"""simple docstring"""






						snake_case        =     math.radians(_UpperCamelCase   )
						snake_case        =     math.radians(_UpperCamelCase   )

						# Convert voltage and current to rectangular form
						snake_case        =     cmath.rect(_UpperCamelCase	,     _UpperCamelCase   )
						snake_case        =     cmath.rect(_UpperCamelCase	,     _UpperCamelCase   )

						# Calculate apparent power
						return voltage_rect * current_rect


if __name__ == "__main__":
					import doctest

					doctest.testmod()


