python - pylint W0622(重新定义内置)在子类中重写 "standard"方法时

标签 python coding-style warnings pylint software-quality

在 Python 中,许多方法使用“标准化”名称定义参数变量,例如:

def __exit__(self, type, value, traceback):

在上面的行中,变量 type 导致 pylint 警告 (W0622) 正在重新定义内置函数:正在重新定义内置“类型”(redefine-builtin).

有很多方法可以解决此问题并让 pylint 满意(重命名变量、添加 pylint 指令 (# pylint:disable=W0622) 来忽略问题等)。

在这些情况下保持良好的代码质量并使 pylint 满意的最佳/首选/建议/常规使用方法(如果有)是什么?

最佳答案

禁用 pylint 警告可能被认为是一种不好的做法。

引用quantifiedcode.com :

In order for __exit__ to work properly it must have exactly three arguments: exception_type, exception_value, and traceback. The formal argument names in the method definition do not need to correspond directly to these names, but they must appear in this order.

因此,使用元组打包是一个不错的选择def __exit__(self, *exc)

这是官方文档中建议的内容: https://docs.python.org/3/library/contextlib.html

关于python - pylint W0622(重新定义内置)在子类中重写 "standard"方法时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56056551/

相关文章:

c++ - 允许仅使用动态分配来分配对象

c++ - gcc 的 -Wconversion 是否与使用比 int 短的整数类型的复合赋值(+= 等)不兼容?

.net - 警告 : Found conflicts between different versions of the same dependent assembly

Python,if 语句不起作用 - Blynk Raspberry Pi

具有定义边缘的 Python 3 OpenCV 颜色对象检测

python - 水平多位过滤器不起作用 django admin

c++ - 服务器端警告 : Aggregation query used without partition key

python - 如果值相等,则将连续的子列表分组在一起,然后提取具有属性 = 'R' 的值

c++ - 在 C/C++ 中,任何人都可以提供一些使用内联或宏编写小函数的经验法则吗?

generics - Swift 中什么时候需要或需要泛型函数?