utils/tools/func_handle.py

32 lines
876 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
# @Time : 2023/4/6 11:36
# @Author : Flora.Chen
# @File : helper.py
# @Software: PyCharm
# @Desc:
def add_docstring(docstring):
"""
函数装饰器它接受一个字符串参数docstring
并返回一个装饰器函数。装饰器函数接受一个函数参数func
并将func的__doc__属性设置为docstring。
"""
def decorator(func):
func.__doc__ = docstring
return func
return decorator
class AddCLassDocstring:
"""
类装饰器它接受一个字符串参数docstring
并返回一个装饰器函数。装饰器函数接受一个函数参数func
并将func的__doc__属性设置为docstring。
"""
def __init__(self, docstring):
self.docstring = docstring
def __call__(self, func):
func.__doc__ = self.docstring
return func