隐藏一些可能不是成员的 Pylint 错误 [英] Hide some maybe-no-member Pylint errors

查看:39
本文介绍了隐藏一些可能不是成员的 Pylint 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pylint 分析了以下 Python 片段代码:

The following Python fragment code gets analyzed by Pylint:

if type(result) is array.array:
    read = result.tobytes()

... 最后一行出现以下错误:

... with the following error for the last line:

E:401,22: Instance of 'int' has no 'tobytes' member\ 
 (but some types could not be inferred) (maybe-no-member)

result 变量是从外部函数接收的.如何更改(更正)代码以使 Pylint 理解?或者我怎么能告诉它函数的结果可以有除 int 之外的其他类型?或者我如何告诉它忽略该特定行?(我倾向于按照问题的顺序回答)

The result variable is received from an external function. How can I change (correct) the code to make Pylint understand? Or how can I tell it that the result of the function can have other types than int? Or how can I tell it to ignore that particular line? (I favor an answer in this order of the questions)

推荐答案

出于某种原因,pylint 没有得到 'result' 可能是数组类型(并且肯定会在 'if' 分支下).目前没有办法告诉 pylint 这件事,但希望在某个时候有可能.因此,目前,您只能通过在违规语句之后或正上方添加 # pylint: disable=maybe-no-member 来禁用该特定行的警告.例如:

For some reason, pylint doesn't get 'result' may be of the array type (and will be for sure under the 'if' branch). There is currently no way to tell pylint about that, though it will hopefully be possible at some point. So for now, you can only disable the warning for that specific line by adding # pylint: disable=maybe-no-member after the offending statement or right above it. For example:

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()

这篇关于隐藏一些可能不是成员的 Pylint 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆