简体   繁体   English

Pylint 没有捕捉到“局部变量 'xyz' 可能在赋值之前被引用”但 PyCharm 使用 python 2.7 突出显示相同

[英]Pylint is not catching "Local variable 'xyz' might be referenced before assignment " but PyCharm is highlighing the same, using python 2.7

        if goal:
            checkA = checkAfunc(user, goal)
            if not checkA:
                if goal:
                    xyz, _ = checkB(user, goal)
                else
                    xyz, _ = checkB(user, goal)
            checkA = xyz or checkA

While refactoring the above code, it got committed without throwing any exception.在重构上面的代码时,它没有抛出任何异常就被提交了。 pylint check is also not emitting any error While pycharm also uses pylint , it shows - Local variable 'xyz' might be referenced before assignment. pylint 检查也不会发出任何错误虽然 pycharm 也使用 pylint ,但它显示 - 局部变量 'xyz' 可能在赋值之前被引用。 What rule shall be further added in pylint config for emitting this exception before committing the code itself?在提交代码本身之前,应在 pylint 配置中进一步添加什么规则来发出此异常?

pylint reports for un-initialized/un-defined variable , if only it can be statically so determined . pylint 报告未初始化/未定义的变量,只要它可以静态地确定。 for eg ,pylint will not warn for x being un-defined in the following piece of code (as it is pure static analysis tool)例如,pylint 不会警告 x 在以下代码中未定义(因为它是纯静态分析工具)

y=10
if  y==4:
    x=5
print(x)

pycharm does not use pylint by default. pycharm 默认不使用 pylint。 You will have to specifically configure pylint to be used.您必须专门配置要使用的 pylint。 pycharm has its own inbuilt checker, which seems to check for conditional paths too. pycharm 有自己的内置检查器,它似乎也检查条件路径。 pycharm will warn you pycharm 会警告你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM