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







def        SCREAMING_SNAKE_CASE__			(     __A=None    ,       __A=None			) ->			Tuple:
	return field(default_factory=lambda: default    ,       metadata=__A			)


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= 42
							__lowercase   	= 42
							__lowercase   	= 42
							__lowercase   	= 42


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= 42
							__lowercase   	= field(default="""toto"""		,     metadata={"""help""": """help message"""}		)


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= False
							__lowercase   	= True
							__lowercase   	= None


class 		__UpperCAmelCase   (      _lowerCamelCase		):
							__lowercase   	= """titi"""
							__lowercase   	= """toto"""


class 		__UpperCAmelCase   (      _lowerCamelCase		):
							__lowercase   	= """titi"""
							__lowercase   	= """toto"""
							__lowercase   	= 42


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= "toto"


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	BasicEnum(self.foo						)


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= "toto"


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	MixedTypeEnum(self.foo						)


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= None
							__lowercase   	= field(default=_lowerCamelCase		,     metadata={"""help""": """help message"""}		)
							__lowercase   	= None
							__lowercase   	= list_field(default=[]		)
							__lowercase   	= list_field(default=[]		)


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= list_field(default=[]		)
							__lowercase   	= list_field(default=[1, 2, 3]		)
							__lowercase   	= list_field(default=["""Hallo""", """Bonjour""", """Hello"""]		)
							__lowercase   	= list_field(default=[0.1, 0.2, 0.3]		)


@dataclass
class 		__UpperCAmelCase   :
							__lowercase   	= field()
							__lowercase   	= field()
							__lowercase   	= field()


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	BasicEnum(self.required_enum						)


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


if is_python_no_less_than_3_10:


					@dataclass
					class 		__UpperCAmelCase   :
												__lowercase   	= False
												__lowercase   	= True
												__lowercase   	= None


					@dataclass
					class 		__UpperCAmelCase   :
												__lowercase   	= None
												__lowercase   	= field(default=_lowerCamelCase		,     metadata={"""help""": """help message"""}		)
												__lowercase   	= None
												__lowercase   	= list_field(default=[]		)
												__lowercase   	= list_field(default=[]		)





class 		__UpperCAmelCase   (      unittest.TestCase		):


							def 				lowerCamelCase       ( 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(lowerCAmelCase_						).items() if k != 'container'}
									_snake_case     		=	{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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	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_						)

								_snake_case     		=	['--foo', '1', '--baz', 'quux', '--bar', '0.5']
								((_snake_case)		,				)     		=	parser.parse_args_into_dataclasses(lowerCAmelCase_					,     look_for_args_file=lowerCAmelCase_						)
								self.assertFalse(example.flag						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	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_						)

								_snake_case     		=	[WithDefaultBoolExample]
								if is_python_no_less_than_3_10:
									dataclass_types.append(lowerCAmelCase_						)

								for dataclass_type in dataclass_types:
									_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)
									self.argparsersEqual(lowerCAmelCase_					,     lowerCAmelCase_						)

									_snake_case     		=	parser.parse_args([]						)
									self.assertEqual(lowerCAmelCase_					,     Namespace(foo=lowerCAmelCase_					,     baz=lowerCAmelCase_					,     opt=lowerCAmelCase_						)						)

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

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

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

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


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

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

								_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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								@dataclass
								class 		__UpperCAmelCase   :
															__lowercase   	= "toto"
								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

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

								_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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	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_						)

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

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


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	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_						)

								_snake_case     		=	[OptionalExample]
								if is_python_no_less_than_3_10:
									dataclass_types.append(lowerCAmelCase_						)

								for dataclass_type in dataclass_types:
									_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

									self.argparsersEqual(lowerCAmelCase_					,     lowerCAmelCase_						)

									_snake_case     		=	parser.parse_args([]						)
									self.assertEqual(lowerCAmelCase_					,     Namespace(foo=lowerCAmelCase_					,     bar=lowerCAmelCase_					,     baz=lowerCAmelCase_					,     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(lowerCAmelCase_					,     Namespace(foo=12					,     bar=3.14					,     baz='42'					,     ces=['a', 'b', 'c']					,     des=[1, 2, 3]						)						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	{
								    'foo': 12,
								    'bar': 3.14,
								    'baz': '42',
								    'flag': True,
								}

								_snake_case     		=	parser.parse_dict(lowerCAmelCase_						)[0]
								_snake_case     		=	BasicExample(**lowerCAmelCase_						)
								self.assertEqual(lowerCAmelCase_					,     lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

								_snake_case     		=	{
								    'foo': 12,
								    'bar': 3.14,
								    'baz': '42',
								    'flag': True,
								    'extra': 42,
								}

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


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

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

								_snake_case     		=	BasicExample(**lowerCAmelCase_						)
								self.assertEqual(lowerCAmelCase_					,     lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)

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




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	HfArgumentParser(lowerCAmelCase_						)
								self.assertIsNotNone(lowerCAmelCase_						)



'''simple docstring'''







import math







def        SCREAMING_SNAKE_CASE__			(     __A    ,       __A			) ->			float:
	if (
	    not isinstance(__A    ,       (int, float)			)
	    or power_factor < -1
	    or power_factor > 1
	):
		raise ValueError('power_factor must be a valid float value between -1 and 1.'			)
	return apparent_power * power_factor







def        SCREAMING_SNAKE_CASE__			(     __A    ,       __A			) ->			float:
	if (
	    not isinstance(__A    ,       (int, float)			)
	    or power_factor < -1
	    or power_factor > 1
	):
		raise ValueError('power_factor must be a valid float value between -1 and 1.'			)
	return apparent_power * math.sqrt(1 - power_factor**2			)


if __name__ == "__main__":
					import doctest

					doctest.testmod()

