"""Representation modification for Hoshi CapSule (:mod:`qurry.capsule.hoshi.repr_modify`)I write this module just for having better representation for the functions:func:`~qurry.capsule.internet_is_fxxking_awesome`. :3"""fromtypingimportAny,Callable,Union,OptionalclassEasyReprModify:"""Easy representation modification."""def__init__(self,fn:Callable[...,Any],repr_content:Optional[Union[str,Callable[...,str]]]=None,):"""Initialize the :class:`EasyReprModify`. Args: fn (Callable[..., Any]): The function to be modified. repr_content (Optional[Union[str, Callable[..., str]]], optional): The content of the representation. If it is a string, it will be the representation. If it is a function, it will be the representation function. Defaults to None, which means it will use the function's `__repr__`. """self._fn=fnifisinstance(repr_content,str):self._repr=lambda:repr_contentelifisinstance(repr_content,Callable):self._repr=repr_contentelse:self._repr=self._fn.__repr__@propertydef__doc__(self)->Optional[str]:returnself._fn.__doc__@__doc__.setterdef__doc__(self,val:Optional[str])->None:self._fn.__doc__=valdef__call__(self,*args:Any,**kwargs:Any)->Any:returnself._fn(*args,**kwargs)def__repr__(self):returnself._repr()
[docs]defeasy_repr_modify_wrapper(repr_content:Optional[Union[str,Callable[...,str]]],)->Callable[...,Any]:"""Wrapper for easy representation modification. Args: repr_content (Optional[Union[str, Callable[..., str]]]): The content of the representation. If it is a string, it will be the representation. If it is a function, it will be the representation function. Returns: Callable[..., Any]: The wrapper function for the representation modification. """defwrapper_fn(fn:Callable[...,Any],)->Callable[...,Any]:"""The wrapper function for the representation modification. Args: fn (Callable[..., Any]): The function to be modified. Returns: Callable[..., Any]: The modified function. """returnEasyReprModify(fn,repr_content)returnwrapper_fn