@wraps注解作用
时间: 2023-09-30 15:13:22 浏览: 88
@wraps注解的作用是在定义装饰器时使用,它可以保留被装饰函数的原有属性,包括函数名、文档字符串、注解和参数签名等重要元信息。通过使用@wraps装饰器,可以避免这些元信息在装饰器中丢失。它的作用是将原函数的元信息复制到装饰器函数中,从而使得被装饰的函数拥有和原函数相同的属性,方便调试和使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Python如何创建装饰器时保留函数元信息](https://download.csdn.net/download/weixin_38662213/13709182)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Python 装饰器中的@wraps()的作用](https://blog.csdn.net/weixin_42262081/article/details/119774190)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文