






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

def    SCREAMING_SNAKE_CASE_							(							__magic_name__					:  int=None	,			__magic_name__					:  str=None					)		->			Optional[int]:






	"""simple docstring"""



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

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     int
	snake_case__							:     float
	snake_case__							:     str
	snake_case__							:     bool

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     int     	=  4_2
	snake_case__							:     str     	=  field(default="""toto"""		,   metadata={"""help""": """help message"""}      )

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     bool     	=  False
	snake_case__							:     bool     	=  True
	snake_case__							:     Optional[bool]     	=  None

class     _SCREAMING_SNAKE_CASE       (			__lowercase      ):
	snake_case__							:     Optional[int]     	=  "titi"
	snake_case__							:     str     	=  "toto"

class     _SCREAMING_SNAKE_CASE       (			__lowercase      ):
	snake_case__							:     Dict     	=  "titi"
	snake_case__							:     str     	=  "toto"
	snake_case__							:     Dict     	=  4_2

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     BasicEnum     	=  "toto"





	def 						_A (		self				:					Any	):
		UpperCamelCase     :int          =	BasicEnum(self.foo	)

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     MixedTypeEnum     	=  "toto"





	def 						_A (		self				:					int	):
		UpperCamelCase     :Optional[Any]          =	MixedTypeEnum(self.foo	)

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     Optional[int]     	=  None
	snake_case__							:     Optional[float]     	=  field(default=__lowercase		,   metadata={"""help""": """help message"""}      )
	snake_case__							:     Optional[str]     	=  None
	snake_case__							:     Optional[List[str]]     	=  list_field(default=[]      )
	snake_case__							:     Optional[List[int]]     	=  list_field(default=[]      )

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     List[int]     	=  list_field(default=[]      )
	snake_case__							:     List[int]     	=  list_field(default=[1, 2, 3]      )
	snake_case__							:     List[str]     	=  list_field(default=["""Hallo""", """Bonjour""", """Hello"""]      )
	snake_case__							:     List[float]     	=  list_field(default=[0.1, 0.2, 0.3]      )

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     List[int]     	=  field()
	snake_case__							:     str     	=  field()
	snake_case__							:     BasicEnum     	=  field()





	def 						_A (		self				:					Optional[Any]	):
		UpperCamelCase     :Tuple          =	BasicEnum(self.required_enum	)

@dataclass
class     _SCREAMING_SNAKE_CASE       :
	snake_case__							:     int
	snake_case__							:     "BasicEnum"     	=  field()
	snake_case__							:     "Optional[bool]"     	=  None
	snake_case__							:     "str"     	=  field(default="""toto"""		,   metadata={"""help""": """help message"""}      )
	snake_case__							:     "List[str]"     	=  list_field(default=["""Hallo""", """Bonjour""", """Hello"""]      )


if is_python_no_less_than_3_10:

	@dataclass
	class     _SCREAMING_SNAKE_CASE       :
		snake_case__							:     bool     	=  False
		snake_case__							:     bool     	=  True
		snake_case__							:     bool | None     	=  None

	@dataclass
	class     _SCREAMING_SNAKE_CASE       :
		snake_case__							:     int | None     	=  None
		snake_case__							:     float | None     	=  field(default=__lowercase		,   metadata={"""help""": """help message"""}      )
		snake_case__							:     str | None     	=  None
		snake_case__							:     list[str] | None     	=  list_field(default=[]      )
		snake_case__							:     list[int] | None     	=  list_field(default=[]      )

class     _SCREAMING_SNAKE_CASE       (			unittest.TestCase      ):





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

			self.assertEqual(snake_case_ ,  snake_case_	)





	def 						_A (		self				:					Tuple	):
		UpperCamelCase     :Union[str, Any]          =	HfArgumentParser(snake_case_	)

		UpperCamelCase     :str          =	argparse.ArgumentParser()
		expected.add_argument("""--foo""" ,  type=snake_case_ ,  required=snake_case_	)
		expected.add_argument("""--bar""" ,  type=snake_case_ ,  required=snake_case_	)
		expected.add_argument("""--baz""" ,  type=snake_case_ ,  required=snake_case_	)
		expected.add_argument("""--flag""" ,  type=snake_case_ ,  default=snake_case_ ,  const=snake_case_ ,  nargs="""?"""	)
		self.argparsersEqual(snake_case_ ,  snake_case_	)

		UpperCamelCase     :Optional[Any]          =	['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
		(UpperCamelCase       )     :str          =	parser.parse_args_into_dataclasses(snake_case_ ,  look_for_args_file=snake_case_	)
		self.assertFalse(example.flag	)





	def 						_A (		self				:					Optional[int]	):
		UpperCamelCase     :Optional[int]          =	HfArgumentParser(snake_case_	)

		UpperCamelCase     :Dict          =	argparse.ArgumentParser()
		expected.add_argument("""--foo""" ,  default=42 ,  type=snake_case_	)
		expected.add_argument("""--baz""" ,  default="""toto""" ,  type=snake_case_ ,  help="""help message"""	)
		self.argparsersEqual(snake_case_ ,  snake_case_	)





	def 						_A (		self				:					List[str]	):
		UpperCamelCase     :int          =	argparse.ArgumentParser()
		expected.add_argument("""--foo""" ,  type=snake_case_ ,  default=snake_case_ ,  const=snake_case_ ,  nargs="""?"""	)
		expected.add_argument("""--baz""" ,  type=snake_case_ ,  default=snake_case_ ,  const=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=snake_case_ ,  dest="""baz"""	)
		expected.add_argument("""--opt""" ,  type=snake_case_ ,  default=snake_case_	)

		UpperCamelCase     :int          =	[WithDefaultBoolExample]
		if is_python_no_less_than_3_10:
			dataclass_types.append(snake_case_	)

		for dataclass_type in dataclass_types:
			UpperCamelCase     :Optional[Any]          =	HfArgumentParser(snake_case_	)
			self.argparsersEqual(snake_case_ ,  snake_case_	)

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

			UpperCamelCase     :List[str]          =	parser.parse_args(["""--foo""", """--no_baz"""]	)
			self.assertEqual(snake_case_ ,  Namespace(foo=snake_case_ ,  baz=snake_case_ ,  opt=snake_case_	)	)

			UpperCamelCase     :str          =	parser.parse_args(["""--foo""", """--baz"""]	)
			self.assertEqual(snake_case_ ,  Namespace(foo=snake_case_ ,  baz=snake_case_ ,  opt=snake_case_	)	)

			UpperCamelCase     :Dict          =	parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]	)
			self.assertEqual(snake_case_ ,  Namespace(foo=snake_case_ ,  baz=snake_case_ ,  opt=snake_case_	)	)

			UpperCamelCase     :Optional[int]          =	parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]	)
			self.assertEqual(snake_case_ ,  Namespace(foo=snake_case_ ,  baz=snake_case_ ,  opt=snake_case_	)	)





	def 						_A (		self				:					Optional[int]	):
		UpperCamelCase     :Union[str, Any]          =	HfArgumentParser(snake_case_	)

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

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

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

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





	def 						_A (		self				:					Optional[int]	):

		@dataclass
		class     _SCREAMING_SNAKE_CASE       :
			snake_case__							:     Literal["titi", "toto", 4_2]     	=  "toto"
		UpperCamelCase     :int          =	HfArgumentParser(snake_case_	)

		UpperCamelCase     :List[str]          =	argparse.ArgumentParser()
		expected.add_argument(
		    """--foo""" ,  default="""toto""" ,  choices=("""titi""", """toto""", 42) ,  type=make_choice_type_function(["""titi""", """toto""", 42]	) ,  )
		self.argparsersEqual(snake_case_ ,  snake_case_	)

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

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

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





	def 						_A (		self				:					Dict	):
		UpperCamelCase     :List[Any]          =	HfArgumentParser(snake_case_	)

		UpperCamelCase     :Tuple          =	argparse.ArgumentParser()
		expected.add_argument("""--foo_int""" ,  nargs="""+""" ,  default=[] ,  type=snake_case_	)
		expected.add_argument("""--bar_int""" ,  nargs="""+""" ,  default=[1, 2, 3] ,  type=snake_case_	)
		expected.add_argument("""--foo_str""" ,  nargs="""+""" ,  default=["""Hallo""", """Bonjour""", """Hello"""] ,  type=snake_case_	)
		expected.add_argument("""--foo_float""" ,  nargs="""+""" ,  default=[0.1, 0.2, 0.3] ,  type=snake_case_	)

		self.argparsersEqual(snake_case_ ,  snake_case_	)

		UpperCamelCase     :str          =	parser.parse_args([]	)
		self.assertEqual(
		    snake_case_ ,  Namespace(foo_int=[] ,  bar_int=[1, 2, 3] ,  foo_str=["""Hallo""", """Bonjour""", """Hello"""] ,  foo_float=[0.1, 0.2, 0.3]	) ,  )

		UpperCamelCase     :int          =	parser.parse_args("""--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7""".split()	)
		self.assertEqual(snake_case_ ,  Namespace(foo_int=[1] ,  bar_int=[2, 3] ,  foo_str=["""a""", """b""", """c"""] ,  foo_float=[0.1, 0.7]	)	)





	def 						_A (		self				:					Dict	):
		UpperCamelCase     :Dict          =	argparse.ArgumentParser()
		expected.add_argument("""--foo""" ,  default=snake_case_ ,  type=snake_case_	)
		expected.add_argument("""--bar""" ,  default=snake_case_ ,  type=snake_case_ ,  help="""help message"""	)
		expected.add_argument("""--baz""" ,  default=snake_case_ ,  type=snake_case_	)
		expected.add_argument("""--ces""" ,  nargs="""+""" ,  default=[] ,  type=snake_case_	)
		expected.add_argument("""--des""" ,  nargs="""+""" ,  default=[] ,  type=snake_case_	)

		UpperCamelCase     :Optional[Any]          =	[OptionalExample]
		if is_python_no_less_than_3_10:
			dataclass_types.append(snake_case_	)

		for dataclass_type in dataclass_types:
			UpperCamelCase     :List[Any]          =	HfArgumentParser(snake_case_	)

			self.argparsersEqual(snake_case_ ,  snake_case_	)

			UpperCamelCase     :Dict          =	parser.parse_args([]	)
			self.assertEqual(snake_case_ ,  Namespace(foo=snake_case_ ,  bar=snake_case_ ,  baz=snake_case_ ,  ces=[] ,  des=[]	)	)

			UpperCamelCase     :List[str]          =	parser.parse_args("""--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3""".split()	)
			self.assertEqual(snake_case_ ,  Namespace(foo=12 ,  bar=3.14 ,  baz="""42""" ,  ces=["""a""", """b""", """c"""] ,  des=[1, 2, 3]	)	)





	def 						_A (		self				:					int	):
		UpperCamelCase     :str          =	HfArgumentParser(snake_case_	)

		UpperCamelCase     :Union[str, Any]          =	argparse.ArgumentParser()
		expected.add_argument("""--required_list""" ,  nargs="""+""" ,  type=snake_case_ ,  required=snake_case_	)
		expected.add_argument("""--required_str""" ,  type=snake_case_ ,  required=snake_case_	)
		expected.add_argument(
		    """--required_enum""" ,  type=make_choice_type_function(["""titi""", """toto"""]	) ,  choices=["""titi""", """toto"""] ,  required=snake_case_ ,  )
		self.argparsersEqual(snake_case_ ,  snake_case_	)





	def 						_A (		self				:					Dict	):
		UpperCamelCase     :Tuple          =	HfArgumentParser(snake_case_	)

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





	def 						_A (		self				:					Dict	):
		UpperCamelCase     :int          =	HfArgumentParser(snake_case_	)

		UpperCamelCase     :Optional[int]          =	{
		    '''foo''': 12,
		    '''bar''': 3.14,
		    '''baz''': '''42''',
		    '''flag''': True,
		}

		UpperCamelCase     :Any          =	parser.parse_dict(snake_case_	)[0]
		UpperCamelCase     :Tuple          =	BasicExample(**snake_case_	)
		self.assertEqual(snake_case_ ,  snake_case_	)





	def 						_A (		self				:					int	):
		UpperCamelCase     :Tuple          =	HfArgumentParser(snake_case_	)

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

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





	def 						_A (		self				:					List[Any]	):
		UpperCamelCase     :Union[str, Any]          =	HfArgumentParser(snake_case_	)

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

		UpperCamelCase     :List[Any]          =	BasicExample(**snake_case_	)
		self.assertEqual(snake_case_ ,  snake_case_	)





	def 						_A (		self				:					int	):
		UpperCamelCase     :Any          =	HfArgumentParser(snake_case_	)

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





	def 						_A (		self				:					List[Any]	):
		UpperCamelCase     :Optional[int]          =	HfArgumentParser(snake_case_	)
		self.assertIsNotNone(snake_case_	)


import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowercase__       ={
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

lowercase__       =logging.WARNING




def    __UpperCamelCase     (				):
 __a :  Optional[Any]						=  os.getenv('''DATASETS_VERBOSITY'''  ,   lowerCAmelCase__  )
 if env_level_str:
  if env_level_str in log_levels:
   return log_levels[env_level_str]
  else:
   logging.getLogger().warning(
       f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
       f"has to be one of: { ', '.join(log_levels.keys()  ) }"  )
 return _default_log_level




def    __UpperCamelCase     (				):
 return __name__.split('''.'''  )[0]




def    __UpperCamelCase     (				):
 return logging.getLogger(_get_library_name()  )




def    __UpperCamelCase     (				):
 # Apply our default configuration to the library root logger.
 __a :  str						=  _get_library_root_logger()
 library_root_logger.setLevel(_get_default_logging_level()  )




def    __UpperCamelCase     (				):
 __a :  Any						=  _get_library_root_logger()
 library_root_logger.setLevel(logging.NOTSET  )




def    __UpperCamelCase     (				lowerCAmelCase__							:				Optional[str] = None  ):
 if name is None:
  __a :  Union[str, Any]						=  _get_library_name()
 return logging.getLogger(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return _get_library_root_logger().getEffectiveLevel()




def    __UpperCamelCase     (				lowerCAmelCase__							:				int  ):
 _get_library_root_logger().setLevel(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 return set_verbosity(lowerCAmelCase__  )




def    __UpperCamelCase     (				):
 __a :  Union[str, Any]						=  False




def    __UpperCamelCase     (				):
 __a :  Tuple						=  True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()



class 		UpperCamelCase__  :
   def __init__(self :					str					,				*snake_case_ :					str					,				**snake_case_ :					Union[str, Any]   ):  # pylint: disable=unused-argument
    __a :  Optional[Any]						=  args[0] if args else None
   def __iter__(self :					List[str]   ):
    return iter(self._iterator   )
   def __getattr__(self :					str					,				snake_case_ :					Optional[Any]   ):

    def empty_fn(*snake_case_ :					int					,				**snake_case_ :					int   ):  # pylint: disable=unused-argument
     return

    return empty_fn
   def __enter__(self :					Union[str, Any]   ):
    return self







   def __exit__(self :					str					,				snake_case_ :					List[str]					,				snake_case_ :					int					,				snake_case_ :					Optional[Any]   ):
    return





lowercase__       =True



class 		UpperCamelCase__  :
   def __call__(self :					Tuple					,				*snake_case_ :					str					,				snake_case_ :					str=False					,				**snake_case_ :					Dict   ):
    if _tqdm_active and not disable:
     return tqdm_lib.tqdm(*snake_case_					,				**snake_case_   )
    else:
     return EmptyTqdm(*snake_case_					,				**snake_case_   )
   def       lowerCAmelCase			(self :					Optional[Any]					,				*snake_case_ :					Union[str, Any]					,				**snake_case_ :					Optional[Any]   ):
    __a :  List[Any]						=  None
    if _tqdm_active:
     return tqdm_lib.tqdm.set_lock(*snake_case_					,				**snake_case_   )







   def       lowerCAmelCase			(self :					str   ):
    if _tqdm_active:
     return tqdm_lib.tqdm.get_lock()





lowercase__       =_tqdm_cls()




def    __UpperCamelCase     (				):
 global _tqdm_active
 return bool(_tqdm_active  )




def    __UpperCamelCase     (				):
 global _tqdm_active
 __a :  Dict						=  True




def    __UpperCamelCase     (				):
 global _tqdm_active
 __a :  Union[str, Any]						=  False
