隐藏一些可能不是成员的 Pylint 错误

编程入门 行业动态 更新时间:2024-10-25 10:34:15
本文介绍了隐藏一些可能不是成员的 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 错误

本文发布于:2023-08-04 03:21:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成员   错误   Pylint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!