以下Python片段代码由进行分析Pylint:
Python
Pylint
if type(result) is array.array: read = result.tobytes()
…最后一行出现以下错误:
E:401,22: Instance of 'int' has no 'tobytes' member\ (but some types could not be inferred) (maybe-no-member)
该result变量是从外部函数接收的。如何更改(正确)代码以使Pylint理解?或者我怎么能说函数的结果可以有除int之外的其他类型?或者我如何告诉它忽略该特定行?(我赞成按问题的顺序回答)
result
由于某些原因,pylint不会获得“结果”可能是数组类型(并且肯定会在“ if”分支下)。目前尚无办法告诉pylint,尽管希望在某个时候有可能。因此,目前,您只能通过# pylint: disable=maybe-no- member在违规语句之后或上方添加该行来禁用该特定行的警告。例如:
# pylint: disable=maybe-no- member
if type(result) is array.array: read = result.tobytes() # pylint: disable=maybe-no-member
要么
if type(result) is array.array: # pylint: disable=maybe-no-member read = result.tobytes()