【发布时间】:2014-10-30 15:36:54
【问题描述】:
Pylint 分析以下Python 片段代码:
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?或者我怎么能告诉它忽略那条特定的行? (我赞成按问题顺序回答)
【问题讨论】:
-
除了
,你还期望有哪些类型? (str 或 bin ..) -
array和int就够了 -
如果之前检查类型会怎样。 if isinstance(result, int) == False: read = result.tobytes()
-
@user3378649 不,但我更喜欢“isinstance(result, array.array)”,谢谢
-
@user3378649 我仍然有错误,只是我更喜欢
isinstance风格而不是type比较。你不觉得我会坚持要一个正确的答案来奖励你吗?
标签: python python-3.4 pylint