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 错误
发布评论