

"""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
snake_case_   :   Tuple        =       sys.version_info >= (3, 1_0)



def   lowercase_	(    _lowercase       :		List[Any]=None							,      _lowercase       :		List[Any]=None	):




     '''simple docstring'''






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







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						42
   SCREAMING_SNAKE_CASE__     				=						42
   SCREAMING_SNAKE_CASE__     				=						42
   SCREAMING_SNAKE_CASE__     				=						42







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







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						False
   SCREAMING_SNAKE_CASE__     				=						True
   SCREAMING_SNAKE_CASE__     				=						None







class       snake_case__  ( lowerCAmelCase_     ):
   SCREAMING_SNAKE_CASE__     				=						"""titi"""
   SCREAMING_SNAKE_CASE__     				=						"""toto"""







class       snake_case__  ( lowerCAmelCase_     ):
   SCREAMING_SNAKE_CASE__     				=						"""titi"""
   SCREAMING_SNAKE_CASE__     				=						"""toto"""
   SCREAMING_SNAKE_CASE__     				=						42







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						"toto"







   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Optional[int]      =				BasicEnum(self.foo  )







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						"toto"







   def 			__lowerCAmelCase				(			self			: int  ):





        '''simple docstring'''



        UpperCAmelCase			:   List[Any]      =				MixedTypeEnum(self.foo  )







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						None
   SCREAMING_SNAKE_CASE__     				=						field(default=lowerCAmelCase_					,  metadata={'''help''': '''help message'''}     )
   SCREAMING_SNAKE_CASE__     				=						None
   SCREAMING_SNAKE_CASE__     				=						list_field(default=[]     )
   SCREAMING_SNAKE_CASE__     				=						list_field(default=[]     )







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						list_field(default=[]     )
   SCREAMING_SNAKE_CASE__     				=						list_field(default=[1, 2, 3]     )
   SCREAMING_SNAKE_CASE__     				=						list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']     )
   SCREAMING_SNAKE_CASE__     				=						list_field(default=[0.1, 0.2, 0.3]     )







@dataclass
class       snake_case__  :
   SCREAMING_SNAKE_CASE__     				=						field()
   SCREAMING_SNAKE_CASE__     				=						field()
   SCREAMING_SNAKE_CASE__     				=						field()







   def 			__lowerCAmelCase				(			self			: Optional[Any]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Tuple      =				BasicEnum(self.required_enum  )







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


if is_python_no_less_than_3_10:







 @dataclass
 class       snake_case__  :
    SCREAMING_SNAKE_CASE__     				=						False
    SCREAMING_SNAKE_CASE__     				=						True
    SCREAMING_SNAKE_CASE__     				=						None







 @dataclass
 class       snake_case__  :
    SCREAMING_SNAKE_CASE__     				=						None
    SCREAMING_SNAKE_CASE__     				=						field(default=lowerCAmelCase_					,  metadata={'''help''': '''help message'''}     )
    SCREAMING_SNAKE_CASE__     				=						None
    SCREAMING_SNAKE_CASE__     				=						list_field(default=[]     )
    SCREAMING_SNAKE_CASE__     				=						list_field(default=[]     )







class       snake_case__  ( unittest.TestCase     ):







   def 			__lowerCAmelCase				(			self			: Dict			,  lowercase			: argparse.ArgumentParser			,  lowercase			: argparse.ArgumentParser  ):





        '''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(lowercase  ).items() if k != "container"}
             UpperCAmelCase			:   str      =				{k: v for k, v in vars(lowercase  ).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"			,  lowercase  ) and yy.get("choices"			,  lowercase  ):
                  for expected_choice in yy["choices"] + xx["choices"]:
                       self.assertEqual(xx["type"](lowercase  )			,  yy["type"](lowercase  )  )
                  del xx["type"], yy["type"]

             self.assertEqual(lowercase			,  lowercase  )







   def 			__lowerCAmelCase				(			self			: str  ):





        '''simple docstring'''



        UpperCAmelCase			:   int      =				HfArgumentParser(lowercase  )

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

        UpperCAmelCase			:   Any      =				["--foo", "1", "--baz", "quux", "--bar", "0.5"]
        ((UpperCAmelCase  )      ,							  )			:   List[str]      =				parser.parse_args_into_dataclasses(lowercase			,  look_for_args_file=lowercase  )
        self.assertFalse(example.flag  )







   def 			__lowerCAmelCase				(			self			: int  ):





        '''simple docstring'''



        UpperCAmelCase			:   Dict      =				HfArgumentParser(lowercase  )

        UpperCAmelCase			:   Optional[Any]      =				argparse.ArgumentParser()
        expected.add_argument("--foo"			,  default=42			,  type=lowercase  )
        expected.add_argument("--baz"			,  default="toto"			,  type=lowercase			,  help="help message"  )
        self.argparsersEqual(lowercase			,  lowercase  )







   def 			__lowerCAmelCase				(			self			: Any  ):





        '''simple docstring'''



        UpperCAmelCase			:   Dict      =				argparse.ArgumentParser()
        expected.add_argument("--foo"			,  type=lowercase			,  default=lowercase			,  const=lowercase			,  nargs="?"  )
        expected.add_argument("--baz"			,  type=lowercase			,  default=lowercase			,  const=lowercase			,  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=lowercase			,  dest="baz"  )
        expected.add_argument("--opt"			,  type=lowercase			,  default=lowercase  )

        UpperCAmelCase			:   Optional[Any]      =				[WithDefaultBoolExample]
        if is_python_no_less_than_3_10:
             dataclass_types.append(lowercase  )

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

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

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

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

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

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







   def 			__lowerCAmelCase				(			self			: str  ):





        '''simple docstring'''



        UpperCAmelCase			:   Any      =				HfArgumentParser(lowercase  )

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

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

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

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







   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        @dataclass
        class       snake_case__  :
           SCREAMING_SNAKE_CASE__     				=						"toto"

        UpperCAmelCase			:   Any      =				HfArgumentParser(lowercase  )

        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(lowercase			,  lowercase  )

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

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

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







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





        '''simple docstring'''



        UpperCAmelCase			:   Optional[int]      =				HfArgumentParser(lowercase  )

        UpperCAmelCase			:   Union[str, Any]      =				argparse.ArgumentParser()
        expected.add_argument("--foo_int"			,  nargs="+"			,  default=[]			,  type=lowercase  )
        expected.add_argument("--bar_int"			,  nargs="+"			,  default=[1, 2, 3]			,  type=lowercase  )
        expected.add_argument("--foo_str"			,  nargs="+"			,  default=["Hallo", "Bonjour", "Hello"]			,  type=lowercase  )
        expected.add_argument("--foo_float"			,  nargs="+"			,  default=[0.1, 0.2, 0.3]			,  type=lowercase  )

        self.argparsersEqual(lowercase			,  lowercase  )

        UpperCAmelCase			:   Union[str, Any]      =				parser.parse_args([]  )
        self.assertEqual(
            lowercase			,  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(lowercase			,  Namespace(foo_int=[1]			,  bar_int=[2, 3]			,  foo_str=["a", "b", "c"]			,  foo_float=[0.1, 0.7]  )  )







   def 			__lowerCAmelCase				(			self			: List[Any]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Tuple      =				argparse.ArgumentParser()
        expected.add_argument("--foo"			,  default=lowercase			,  type=lowercase  )
        expected.add_argument("--bar"			,  default=lowercase			,  type=lowercase			,  help="help message"  )
        expected.add_argument("--baz"			,  default=lowercase			,  type=lowercase  )
        expected.add_argument("--ces"			,  nargs="+"			,  default=[]			,  type=lowercase  )
        expected.add_argument("--des"			,  nargs="+"			,  default=[]			,  type=lowercase  )

        UpperCAmelCase			:   str      =				[OptionalExample]
        if is_python_no_less_than_3_10:
             dataclass_types.append(lowercase  )

        for dataclass_type in dataclass_types:
             UpperCAmelCase			:   Dict      =				HfArgumentParser(lowercase  )

             self.argparsersEqual(lowercase			,  lowercase  )

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

             UpperCAmelCase			:   Dict      =				parser.parse_args("--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3".split()  )
             self.assertEqual(lowercase			,  Namespace(foo=12			,  bar=3.1_4			,  baz="42"			,  ces=["a", "b", "c"]			,  des=[1, 2, 3]  )  )







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





        '''simple docstring'''



        UpperCAmelCase			:   Dict      =				HfArgumentParser(lowercase  )

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







   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Union[str, Any]      =				HfArgumentParser(lowercase  )

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







   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Any      =				HfArgumentParser(lowercase  )

        UpperCAmelCase			:   Any      =				{
            "foo": 12,
            "bar": 3.1_4,
            "baz": "42",
            "flag": True,
        }

        UpperCAmelCase			:   List[str]      =				parser.parse_dict(lowercase  )[0]
        UpperCAmelCase			:   str      =				BasicExample(**lowercase  )
        self.assertEqual(lowercase			,  lowercase  )







   def 			__lowerCAmelCase				(			self			: List[Any]  ):





        '''simple docstring'''



        UpperCAmelCase			:   List[str]      =				HfArgumentParser(lowercase  )

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

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







   def 			__lowerCAmelCase				(			self			: str  ):





        '''simple docstring'''



        UpperCAmelCase			:   Optional[Any]      =				HfArgumentParser(lowercase  )

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

        UpperCAmelCase			:   Tuple      =				BasicExample(**lowercase  )
        self.assertEqual(lowercase			,  lowercase  )







   def 			__lowerCAmelCase				(			self			: Dict  ):





        '''simple docstring'''



        UpperCAmelCase			:   Tuple      =				HfArgumentParser(lowercase  )

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







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





        '''simple docstring'''



        UpperCAmelCase			:   List[Any]      =				HfArgumentParser(lowercase  )
        self.assertIsNotNone(lowercase  )





"""simple docstring"""






from __future__ import annotations

snake_case_   :   str        =       list[list[int]]

# assigning initial values to the grid
snake_case_   :   Matrix        =       [
    [3, 0, 6, 5, 0, 8, 4, 0, 0],
    [5, 2, 0, 0, 0, 0, 0, 0, 0],
    [0, 8, 7, 0, 0, 0, 0, 3, 1],
    [0, 0, 3, 0, 1, 0, 0, 8, 0],
    [9, 0, 0, 8, 6, 3, 0, 0, 5],
    [0, 5, 0, 0, 9, 0, 6, 0, 0],
    [1, 3, 0, 0, 0, 0, 2, 5, 0],
    [0, 0, 0, 0, 0, 0, 0, 7, 4],
    [0, 0, 5, 2, 0, 6, 3, 0, 0],
]

# a grid with no solution
snake_case_   :   Matrix        =       [
    [5, 0, 6, 5, 0, 8, 4, 0, 3],
    [5, 2, 0, 0, 0, 0, 0, 0, 2],
    [1, 8, 7, 0, 0, 0, 0, 3, 1],
    [0, 0, 3, 0, 1, 0, 0, 8, 0],
    [9, 0, 0, 8, 6, 3, 0, 0, 5],
    [0, 5, 0, 0, 9, 0, 6, 0, 0],
    [1, 3, 0, 0, 0, 0, 2, 5, 0],
    [0, 0, 0, 0, 0, 0, 0, 7, 4],
    [0, 0, 5, 2, 0, 6, 3, 0, 0],
]



def   lowercase_	(    _lowercase       :		Matrix							,      _lowercase       :		int							,      _lowercase       :		int							,      _lowercase       :		int	):




					'''simple docstring'''






					for i in range(9	):
										if grid[row][i] == n or grid[i][column] == n:
															return False

					for i in range(3	):
										for j in range(3	):
															if grid[(row - row % 3) + i][(column - column % 3) + j] == n:
																				return False

					return True



def   lowercase_	(    _lowercase       :		Matrix	):




					'''simple docstring'''






					for i in range(9	):
										for j in range(9	):
															if grid[i][j] == 0:
																				return i, j
					return None



def   lowercase_	(    _lowercase       :		Matrix	):




					'''simple docstring'''






					if location := find_empty_location(_lowercase	):
										UpperCAmelCase      ,							UpperCAmelCase			:   List[str]      =				location
					else:
										# If the location is ``None``, then the grid is solved.
										return grid

					for digit in range(1							,      10	):
										if is_safe(_lowercase							,      _lowercase							,      _lowercase							,      _lowercase	):
															UpperCAmelCase			:   int      =				digit

															if sudoku(_lowercase	) is not None:
																				return grid

															UpperCAmelCase			:   Optional[Any]      =				0

					return None



def   lowercase_	(    _lowercase       :		Matrix	):




					'''simple docstring'''






					for row in grid:
										for cell in row:
															print(_lowercase							,      end=" "	)
										print()


if __name__ == "__main__":
	# make a copy of grid so that you can compare with the unmodified grid
	for example_grid in (initial_grid, no_solution):
		print("""\nExample grid:\n""" + """=""" * 2_0)
		print_solution(example_grid)
		print("""\nExample grid solution:""")
		snake_case_   :   Dict        =       sudoku(example_grid)
		if solution is not None:
			print_solution(solution)
		else:
			print("""Cannot find a solution.""")


