如何忽略PyDev中的特定警告?

时间:2014-02-16 03:14:02

标签: eclipse warnings pydev ignore

如何忽略Eclipse中的特定警告?

我正在做ZetCode的PyQt4 tutorial LPTHW样式(是的,我正在使用PyDev),并添加有用的注释,以便我可以将它作为参考。 Eclipse正在困扰我一个未使用的变量。 (正在使用,因为初始化函数会自动运行代码。只是要清楚。)

我不想为整个文件关闭它,因为在大多数情况下这实际上很方便。我只是想忽略那个警告。

提前致谢。

2 个答案:

答案 0 :(得分:0)

之前有人问过这个问题。看看您需要的答案是here

答案 1 :(得分:0)

要禁止显示特定行的警告,您唯一的选择是在该行中添加诸如#@UnusedVariable之类的注释:

def foo():
    x = 5 # @UnusedVariable
    return 10

要禁止显示其他类型的警告,请参见PyDev source code中的禁止字符串常量列表:

public static final String MSG_TO_IGNORE_TYPE_UNUSED_IMPORT = "@UnusedImport";
public static final String MSG_TO_IGNORE_TYPE_UNUSED_WILD_IMPORT = "@UnusedWildImport";
public static final String MSG_TO_IGNORE_TYPE_UNUSED_VARIABLE = "@UnusedVariable";
public static final String MSG_TO_IGNORE_TYPE_UNDEFINED_VARIABLE = "@UndefinedVariable";
public static final String MSG_TO_IGNORE_TYPE_DUPLICATED_SIGNATURE = "@DuplicatedSignature";
public static final String MSG_TO_IGNORE_TYPE_REIMPORT = "@Reimport";
public static final String MSG_TO_IGNORE_TYPE_UNRESOLVED_IMPORT = "@UnresolvedImport";
public static final String MSG_TO_IGNORE_TYPE_NO_SELF = "@NoSelf";
public static final String MSG_TO_IGNORE_TYPE_UNDEFINED_IMPORT_VARIABLE = "@UndefinedVariable";
public static final String MSG_TO_IGNORE_TYPE_UNUSED_PARAMETER = "@UnusedVariable";
public static final String MSG_TO_IGNORE_TYPE_NO_EFFECT_STMT = "@NoEffect";
public static final String MSG_TO_IGNORE_TYPE_INDENTATION_PROBLEM = "@IndentOk";
public static final String MSG_TO_IGNORE_TYPE_ASSIGNMENT_TO_BUILT_IN_SYMBOL = "@ReservedAssignment";
public static final String MSG_TO_IGNORE_TYPE_PEP8 = "@IgnorePep8";
public static final String MSG_TO_IGNORE_TYPE_ARGUMENTS_MISATCH = "@ArgumentMismatch";

例如:

def get_answer(format='string'): # @ReservedAssignment
    answer = 42.0
    if format == 'string':
        return str(answer)
    elif format == 'int':
        return int(answer)
    else:
        return answer