作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用默认设置测试 pylint 并且(请参阅下面的 python 代码)收到警告:
>pylint pylint_test_01.py
>pylint_test_01.py:24:7: W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)
'''Test pylint with default settings warnings'''
from random import randint
def sortaray_builtin(arr):
'''This is built in Python sort function'''
return sorted(arr.copy())
def sortaray_bubble(arr):
'''Bubble sorting algorithm -- is a simplest of sorting algorithms. Perfomance: O(N**2)'''
brr = arr.copy()
for i, _ in enumerate(brr[:-1]):
for j in range(i, len(brr)):
if brr[i] > brr[j]:
brr[i], brr[j] = brr[j], brr[i]
return brr
SFUNCTIONS = [
sortaray_builtin,
sortaray_bubble
]
ARSIZE = 20
ARRY = [randint(0, ARSIZE) for i in range(ARSIZE)]
for SrtFunc in SFUNCTIONS:
# Line below cause an W0143: Comparing against a callable, did you omit the parenthesis? (comparison-with-callable)
if SrtFunc == sortaray_builtin:
print("Builtin: ", end='', flush=True)
else:
print("Bubble : ", end='', flush=True)
print(SrtFunc(ARRY))
最佳答案
选项 1
您可以禁用某些地方的检查。
if SrtFunc == sortaray_builtin: # pylint: disable=W0143
__name__
获取函数的名称属性。
SrtFunc.__name__ == builtin_sort.__name__
.__doc__
SrtFunc.__doc__ == builtin_sort.__doc__
class Sorter():
def __init__(self, func):
self.sort = func
builtin = Sorter(sortaray_builtin)
bubble = Sorter(sortaray_bubble)
SFUNCTIONS = [ builtin, bubble ]
builtin.sort()
关于python - PyLint W0143 警告 : Comparing against a callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60491475/
我是一名优秀的程序员,十分优秀!