



"""simple docstring"""


from importlib import import_module

from .logging import get_logger


snake_case_    					=	get_logger(__name__)







class 				A_      :



						"""simple docstring"""






						def __init__( self			:Tuple       ,  lowercase_			:Union[str, Any]       ,  lowercase_			:Tuple=None )    ->      Any:
												UpperCAmelCase					=			attrs or []
												if module is not None:
																		for key in module.__dict__:
																								if key in attrs or not key.startswith('__' ):
																														setattr(self       ,  lowercase_       ,  getattr(lowercase_       ,  lowercase_ ) )
												UpperCAmelCase					=			module._original_module if isinstance(lowercase_       ,  _PatchedModuleObj ) else module







class 				A_      :



						"""simple docstring"""
						__UpperCamelCase		    =							[]






						def __init__( self			:int       ,  lowercase_			:str       ,  lowercase_			:str       ,  lowercase_			:Dict       ,  lowercase_			:List[Any]=None )    ->      Optional[Any]:
												UpperCAmelCase					=			obj
												UpperCAmelCase					=			target
												UpperCAmelCase					=			new
												UpperCAmelCase					=			target.split('.' )[0]
												UpperCAmelCase					=			{}
												UpperCAmelCase					=			attrs or []






						def __enter__( self			:Tuple )    ->      Any:
												*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(lowercase_ ) ):
																		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       ,  lowercase_ )
																								# 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(lowercase_       ,  _PatchedModuleObj ) and obj_attr._original_module is submodule)
																								):
																														UpperCAmelCase					=			obj_attr
																														# patch at top level
																														setattr(self.obj       ,  lowercase_       ,  _PatchedModuleObj(lowercase_       ,  attrs=self.attrs ) )
																														UpperCAmelCase					=			getattr(self.obj       ,  lowercase_ )
																														# construct lower levels patches
																														for key in submodules[i + 1 :]:
																																				setattr(lowercase_       ,  lowercase_       ,  _PatchedModuleObj(getattr(lowercase_       ,  lowercase_       ,  lowercase_ )       ,  attrs=self.attrs ) )
																																				UpperCAmelCase					=			getattr(lowercase_       ,  lowercase_ )
																														# finally set the target attribute
																														setattr(lowercase_       ,  lowercase_       ,  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(lowercase_ ) )       ,  lowercase_ )
																		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       ,  lowercase_ ) is attr_value:
																														UpperCAmelCase					=			getattr(self.obj       ,  lowercase_ )
																														setattr(self.obj       ,  lowercase_       ,  self.new )
												elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
																		UpperCAmelCase					=			globals()['__builtins__'][target_attr]
																		setattr(self.obj       ,  lowercase_       ,  self.new )
												else:
																		raise RuntimeError(f"""Tried to patch attribute {target_attr} instead of a submodule.""" )






						def __exit__( self			:Optional[int]       ,  *lowercase_			:int )    ->      List[str]:
												for attr in list(self.original ):
																		setattr(self.obj       ,  lowercase_       ,  self.original.pop(lowercase_ ) )






						def      UpperCAmelCase__					( self			:List[Any] )    ->      Optional[int]:
												self.__enter__()
												self._active_patches.append(self )






						def      UpperCAmelCase__					( self			:Optional[Any] )    ->      str:
												try:
																		self._active_patches.remove(self )
												except ValueError:
																		# If the patch hasn't been started this will fail
																		return None

												return self.__exit__()










"""simple docstring"""


def 			_lowerCAmelCase				(       lowercase_						):

						if not isinstance(lowercase_		,     lowercase_						):
												UpperCAmelCase					=			F"""Input value of [number={number}] must be an integer"""
												raise TypeError(lowercase_						)

						if number < 1:
												UpperCAmelCase					=			F"""Input value of [number={number}] must be > 0"""
												raise ValueError(lowercase_						)

						UpperCAmelCase					=			1

						for i in range(1		,     lowercase_						):
												current_number *= 4 * i - 2
												current_number //= i + 1

						return current_number


if __name__ == "__main__":
				import doctest

				doctest.testmod()





