

"""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
__UpperCAmelCase			=					sys.version_info >= (3, 10)
def 	lowerCAmelCase    (       __UpperCamelCase=None				,     __UpperCamelCase=None   ):
 '''simple docstring'''





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







@dataclass
class   __lowercase      :
  snake_case_												=							4_2
  snake_case_												=							4_2
  snake_case_												=							4_2
  snake_case_												=							4_2







@dataclass
class   __lowercase      :
  snake_case_												=							4_2
  snake_case_												=							field(default="""toto"""						,      metadata={"""help""": """help message"""}       )







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







class   __lowercase      (     __lowerCamelCase       ):
  snake_case_												=							"""titi"""
  snake_case_												=							"""toto"""







class   __lowercase      (     __lowerCamelCase       ):
  snake_case_												=							"""titi"""
  snake_case_												=							"""toto"""
  snake_case_												=							4_2







@dataclass
class   __lowercase      :
  snake_case_												=							"""toto"""

  def  __lowercase							(	self		:      Optional[int]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Tuple        =       BasicEnum(self.foo     )







@dataclass
class   __lowercase      :
  snake_case_												=							"""toto"""

  def  __lowercase							(	self		:      Dict     ):






   '''simple docstring'''
   UpperCAmelCase__       :	List[Any]        =       MixedTypeEnum(self.foo     )







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







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







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

  def  __lowercase							(	self		:      Dict     ):






   '''simple docstring'''
   UpperCAmelCase__       :	int        =       BasicEnum(self.required_enum     )







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


if is_python_no_less_than_3_10:







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







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







class   __lowercase      (     unittest.TestCase       ):

  def  __lowercase							(	self		:      str       ,A		:      Tuple       ,A		:      List[str]     ):






   '''simple docstring'''
   self.assertEqual(len(a._actions     )       ,len(b._actions     )     )
   for x, y in zip(a._actions       ,b._actions     ):
    UpperCAmelCase__       :	List[Any]        =       {k: v for k, v in vars(lowerCamelCase_     ).items() if k != """container"""}
    UpperCAmelCase__       :	str        =       {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  __lowercase							(	self		:      Dict     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Dict        =       HfArgumentParser(lowerCamelCase_     )

   UpperCAmelCase__       :	Tuple        =       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_     )

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

  def  __lowercase							(	self		:      Tuple     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Any        =       HfArgumentParser(lowerCamelCase_     )

   UpperCAmelCase__       :	List[Any]        =       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  __lowercase							(	self		:      Union[str, Any]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	int        =       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_     )

   UpperCAmelCase__       :	Dict        =       [WithDefaultBoolExample]
   if is_python_no_less_than_3_10:
    dataclass_types.append(lowerCamelCase_     )

   for dataclass_type in dataclass_types:
    UpperCAmelCase__       :	Dict        =       HfArgumentParser(lowerCamelCase_     )
    self.argparsersEqual(lowerCamelCase_       ,lowerCamelCase_     )

    UpperCAmelCase__       :	Union[str, Any]        =       parser.parse_args([]     )
    self.assertEqual(lowerCamelCase_       ,Namespace(foo=lowerCamelCase_       ,baz=lowerCamelCase_       ,opt=lowerCamelCase_     )     )

    UpperCAmelCase__       :	Dict        =       parser.parse_args(["""--foo""", """--no_baz"""]     )
    self.assertEqual(lowerCamelCase_       ,Namespace(foo=lowerCamelCase_       ,baz=lowerCamelCase_       ,opt=lowerCamelCase_     )     )

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

    UpperCAmelCase__       :	Optional[Any]        =       parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]     )
    self.assertEqual(lowerCamelCase_       ,Namespace(foo=lowerCamelCase_       ,baz=lowerCamelCase_       ,opt=lowerCamelCase_     )     )

    UpperCAmelCase__       :	str        =       parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]     )
    self.assertEqual(lowerCamelCase_       ,Namespace(foo=lowerCamelCase_       ,baz=lowerCamelCase_       ,opt=lowerCamelCase_     )     )

  def  __lowercase							(	self		:      List[str]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Dict        =       HfArgumentParser(lowerCamelCase_     )

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

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

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

   UpperCAmelCase__       :	Dict        =       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  __lowercase							(	self		:      int     ):






   '''simple docstring'''







   @dataclass
   class   __lowercase      :
     snake_case_												=							"""toto"""







   UpperCAmelCase__       :	Dict        =       HfArgumentParser(lowerCamelCase_     )

   UpperCAmelCase__       :	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_     )

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

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

   UpperCAmelCase__       :	List[str]        =       parser.parse_args(["""--foo""", """42"""]     )
   self.assertEqual(args.foo       ,42     )

  def  __lowercase							(	self		:      Tuple     ):






   '''simple docstring'''
   UpperCAmelCase__       :	List[str]        =       HfArgumentParser(lowerCamelCase_     )

   UpperCAmelCase__       :	Optional[Any]        =       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_     )

   UpperCAmelCase__       :	Dict        =       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]     )       ,)

   UpperCAmelCase__       :	Tuple        =       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  __lowercase							(	self		:      Any     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Dict        =       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_     )

   UpperCAmelCase__       :	str        =       [OptionalExample]
   if is_python_no_less_than_3_10:
    dataclass_types.append(lowerCamelCase_     )

   for dataclass_type in dataclass_types:
    UpperCAmelCase__       :	str        =       HfArgumentParser(lowerCamelCase_     )

    self.argparsersEqual(lowerCamelCase_       ,lowerCamelCase_     )

    UpperCAmelCase__       :	List[str]        =       parser.parse_args([]     )
    self.assertEqual(lowerCamelCase_       ,Namespace(foo=lowerCamelCase_       ,bar=lowerCamelCase_       ,baz=lowerCamelCase_       ,ces=[]       ,des=[]     )     )

    UpperCAmelCase__       :	List[Any]        =       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.1_4       ,baz="""42"""       ,ces=["""a""", """b""", """c"""]       ,des=[1, 2, 3]     )     )

  def  __lowercase							(	self		:      int     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Tuple        =       HfArgumentParser(lowerCamelCase_     )

   UpperCAmelCase__       :	Dict        =       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  __lowercase							(	self		:      Union[str, Any]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	str        =       HfArgumentParser(lowerCamelCase_     )

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






   '''simple docstring'''
   UpperCAmelCase__       :	Optional[int]        =       HfArgumentParser(lowerCamelCase_     )

   UpperCAmelCase__       :	Optional[int]        =       {
       """foo""": 12,
       """bar""": 3.1_4,
       """baz""": """42""",
       """flag""": True,
   }

   UpperCAmelCase__       :	Tuple        =       parser.parse_dict(lowerCamelCase_     )[0]
   UpperCAmelCase__       :	Optional[int]        =       BasicExample(**lowerCamelCase_     )
   self.assertEqual(lowerCamelCase_       ,lowerCamelCase_     )

  def  __lowercase							(	self		:      Union[str, Any]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	int        =       HfArgumentParser(lowerCamelCase_     )

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

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

  def  __lowercase							(	self		:      Union[str, Any]     ):






   '''simple docstring'''
   UpperCAmelCase__       :	List[Any]        =       HfArgumentParser(lowerCamelCase_     )

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

   UpperCAmelCase__       :	str        =       BasicExample(**lowerCamelCase_     )
   self.assertEqual(lowerCamelCase_       ,lowerCamelCase_     )

  def  __lowercase							(	self		:      Dict     ):






   '''simple docstring'''
   UpperCAmelCase__       :	List[str]        =       HfArgumentParser(lowerCamelCase_     )

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




  def  __lowercase							(	self		:      Tuple     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Any        =       HfArgumentParser(lowerCamelCase_     )
   self.assertIsNotNone(lowerCamelCase_     )








"""simple docstring"""


class lowerCamelCase__   :



    '''simple docstring'''




    def __init__( self    )    ->      Union[str, Any]:
          A				  =		{}




    def UpperCamelCase__		( self    )    ->      None:
          print(self.vertex    )
          for i in self.vertex:
                print(lowerCamelCase_ ,""" -> """ ,""" -> """.join([str(lowerCamelCase_    ) for j in self.vertex[i]]    )    )




    def UpperCamelCase__		( self ,lowerCamelCase_ ,lowerCamelCase_    )    ->      None:
          # check if vertex is already present,
          if from_vertex in self.vertex:
                self.vertex[from_vertex].append(lowerCamelCase_    )
          else:
                # else make a new vertex
                A				  =		[to_vertex]




    def UpperCamelCase__		( self    )    ->      None:
          # visited array for storing already visited nodes
          A				  =		[False] * len(self.vertex    )

          # call the recursive helper function
          for i in range(len(self.vertex    )    ):
                if not visited[i]:
                      self.dfs_recursive(lowerCamelCase_ ,lowerCamelCase_    )




    def UpperCamelCase__		( self ,lowerCamelCase_ ,lowerCamelCase_    )    ->      None:
          # mark start vertex as visited
          A				  =		True

          print(lowerCamelCase_ ,end=""" """    )

          # Recur for all the vertices that are adjacent to this node
          for i in self.vertex:
                if not visited[i]:
                      self.dfs_recursive(lowerCamelCase_ ,lowerCamelCase_    )


if __name__ == "__main__":
  UpperCAmelCase													=Graph()
  g.add_edge(0, 1)
  g.add_edge(0, 2)
  g.add_edge(1, 2)
  g.add_edge(2, 0)
  g.add_edge(2, 3)
  g.add_edge(3, 3)

  g.print_graph()
  print("DFS:")
  g.dfs()

  # OUTPUT:
  # 0  ->  1 -> 2
  # 1  ->  2
  # 2  ->  0 -> 3
  # 3  ->  3
  # DFS:
  #  0 1 2 3




