【发布时间】:2019-09-11 00:52:53
【问题描述】:
问题
我在 Python 类中有一个方法,我使用 functools.wraps 来分配一个文档字符串。这是我使用的确切代码:
facade.py
#!/usr/bin/env python3
"""Facade."""
from functools import wraps
import back_end
@wraps(back_end.some_method)
def renamed_method(str_to_print): # noinspection PyMissingOrEmptyDocstring
back_end.some_method(str_to_print)
back_end.py
#!/usr/bin/env python3
"""Back End."""
def some_method(some_str: str) -> None:
"""Prints out a string.
Args:
some_str: A string to print
"""
print(some_str)
PyCharm 检查警告 Missing docstring 方法 renamed_method。这就是我的样子:
我在同一行添加了# pylint: disable=C0111,它不会使警告消失。
我怎样才能让这个警告消失?我不想取消全局检查。
我尝试过的
仅供参考,我使用PyCharm CE 2018.3.7。我也刚刚更新到PyCharm CE 2019.2.2 并得到了相同的结果。我使用默认设置,只有我更改的内容是使用 Google 文档字符串格式并检查 Python 的所有检查选项。
#1:灯泡 --> 抑制选项
我看了这个答案:https://stackoverflow.com/a/51148355/11163122
还记录在 PyCharm 的网站 here。
而且我没有得到它承诺的抑制选项。
#2:无检查意见
我也试过:# noinspection PyMissingOrEmptyDocstring(完整列表here)。这是完整的尝试:
@wraps(back_end.some_method)
def renamed_method(str_to_print): # noinspection PyMissingOrEmptyDocstring
back_end.some_method(str_to_print)
以及我所看到的图像:
一边
为什么要使用functools.wraps 装饰器?见facade pattern。
【问题讨论】:
标签: python pycharm static-analysis pylint code-inspection