
from importlib import import_module

from .logging import get_logger


lowerCamelCase__	=							get_logger(__name__)







class        lowerCAmelCase__      :

						def __init__(			self       ,							a       ,							a=None				)					->      Any:


								'''simple docstring'''

								_UpperCamelCase						    =	attrs or []
								if module is not None:
										for key in module.__dict__:
												if key in attrs or not key.startswith("""__"""				):
														setattr(self       ,							a       ,							getattr(a       ,							a				)				)
								_UpperCamelCase						    =	module._original_module if isinstance(a       ,							_PatchedModuleObj				) else module







class        lowerCAmelCase__      :
						UpperCamelCase_							: Dict	=		[]

						def __init__(			self       ,							a       ,							a       ,							a       ,							a=None				)					->      Optional[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	obj
								_UpperCamelCase						    =	target
								_UpperCamelCase						    =	new
								_UpperCamelCase						    =	target.split("""."""				)[0]
								_UpperCamelCase						    =	{}
								_UpperCamelCase						    =	attrs or []

						def __enter__(			self				)					->      Union[str, Any]:


								'''simple docstring'''

								*_UpperCamelCase    ,	_UpperCamelCase						    =	self.target.split("""."""				)

								# Patch modules:
								# it's used to patch attributes of submodules like "os.path.join";
								# in this case we need to patch "os" and "os.path"

								for i in range(len(a				)				):
										try:
												_UpperCamelCase						    =	import_module(""".""".join(submodules[: i + 1]				)				)
										except ModuleNotFoundError:
												continue
										# We iterate over all the globals in self.obj in case we find "os" or "os.path"
										for attr in self.obj.__dir__():
												_UpperCamelCase						    =	getattr(self.obj       ,							a				)
												# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
												# This allows to patch renamed modules like "from os import path as ospath".
												if obj_attr is submodule or (
												    (isinstance(a       ,							_PatchedModuleObj				) and obj_attr._original_module is submodule)
												):
														_UpperCamelCase						    =	obj_attr
														# patch at top level
														setattr(self.obj       ,							a       ,							_PatchedModuleObj(a       ,							attrs=self.attrs				)				)
														_UpperCamelCase						    =	getattr(self.obj       ,							a				)
														# construct lower levels patches
														for key in submodules[i + 1 :]:
																setattr(a       ,							a       ,							_PatchedModuleObj(getattr(a       ,							a       ,							a				)       ,							attrs=self.attrs				)				)
																_UpperCamelCase						    =	getattr(a       ,							a				)
														# finally set the target attribute
														setattr(a       ,							a       ,							self.new				)

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

								if submodules:  # if it's an attribute of a submodule like "os.path.join"
										try:
												_UpperCamelCase						    =	getattr(import_module(""".""".join(a				)				)       ,							a				)
										except (AttributeError, ModuleNotFoundError):
												return
										# We iterate over all the globals in self.obj in case we find "os.path.join"
										for attr in self.obj.__dir__():
												# We don't check for the name of the global, but rather if its value *is* "os.path.join".
												# This allows to patch renamed attributes like "from os.path import join as pjoin".
												if getattr(self.obj       ,							a				) is attr_value:
														_UpperCamelCase						    =	getattr(self.obj       ,							a				)
														setattr(self.obj       ,							a       ,							self.new				)
								elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
										_UpperCamelCase						    =	globals()["""__builtins__"""][target_attr]
										setattr(self.obj       ,							a       ,							self.new				)
								else:
										raise RuntimeError(F'Tried to patch attribute {target_attr} instead of a submodule.'				)

						def __exit__(			self       ,							*a				)					->      Union[str, Any]:


								'''simple docstring'''

								for attr in list(self.original				):
										setattr(self.obj       ,							a       ,							self.original.pop(a				)				)

						def  A_				(			self				)					->      List[Any]:


								'''simple docstring'''

								self.__enter__()
								self._active_patches.append(self				)







						def  A_				(			self				)					->      Any:


								'''simple docstring'''

								try:
										self._active_patches.remove(self				)
								except ValueError:
										# If the patch hasn't been started this will fail
										return None

								return self.__exit__()





def 							__A(lowerCAmelCase )		->				list[list[int]]:

		"""simple docstring"""






		_UpperCamelCase						    =	[]
		if len(lowerCAmelCase ) == 1:
				return [nums.copy()]
		for _ in range(len(lowerCAmelCase ) ):
				_UpperCamelCase						    =	nums.pop(0 )
				_UpperCamelCase						    =	permute(lowerCAmelCase )
				for perm in permutations:
						perm.append(lowerCAmelCase )
				result.extend(lowerCAmelCase )
				nums.append(lowerCAmelCase )
		return result


def 							__A(lowerCAmelCase )		->				Optional[int]:

		"""simple docstring"""






		def backtrack(lowerCAmelCase ):
				if start == len(lowerCAmelCase ) - 1:
						output.append(nums[:] )
				else:
						for i in range(lowerCAmelCase						,  len(lowerCAmelCase ) ):
								_UpperCamelCase    ,	_UpperCamelCase						    =	nums[i], nums[start]
								backtrack(start + 1 )
								_UpperCamelCase    ,	_UpperCamelCase						    =	nums[i], nums[start]  # backtrack

		_UpperCamelCase						    =	[]
		backtrack(0 )
		return output


if __name__ == "__main__":
		import doctest

		# use res to print the data in permute2 function
		lowerCamelCase__	=							permutea([1, 2, 3])
		print(res)
		doctest.testmod()



