Pylint E0202 误报?还是这段代码有问题? [英] Pylint E0202 False Positive? Or is this piece of code wrong?

查看:47
本文介绍了Pylint E0202 误报?还是这段代码有问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一个带有属性的类,但是我们遇到了一个关于 pylint (0.25.1) 的严重问题在下面的代码中,我们正在定义一个带有属性的类,这些属性是在 python 2.6 中引入的然而,pylint 抱怨在 __init__ 方法中 self.aProperty 将覆盖名为 aProperty 的已定义方法.我还粘贴了控制台的输出和 pylint 消息的输出.

I've been working on a class with properties but we ran into a nasty problem with pylint (0.25.1) In the code below we are defining a class with a property which were introduced in python 2.6 However, pylint whines about the fact that in the __init__ method self.aProperty will overwrite the defined method named aProperty. I've also pasted the output from the console and the output of the pylint messages.

这是请向 pylint 开发人员报告"的情况还是这段(示例)代码错误?

Is this a case of 'please report to the pylint devs' or is this piece of (example) code wrong?

"""example module"""

class Example(object):
    """example class"""

    @property
    def aProperty(self):
        """get"""
        print "using getter"
        return self._myPropertyValue

    @aProperty.setter
    def aProperty(self, value):
        """set"""
        print "using setter"
        self._myPropertyValue = value

    def secondPublicMethodToIgnorePylintWarning(self):
        """dummy"""
        return self.aProperty

    def __init__(self):
        """init"""
        self._myPropertyValue = None

        self.aProperty = "ThisStatementWillRaise E0202"

anExample = Example()
print anExample.aProperty

anExample.aProperty = "Second binding"
print anExample.aProperty

控制台输出:

使用setter
使用吸气剂
此声明将引发 E0202
使用 setter
使用吸气剂
第二次绑定

using setter
using getter
ThisStatementWillRaise E0202
using setter
using getter
Second binding

Pylint 输出:

E0202: 7,4:Example.aProperty: 在 test1 第 26 行影响的属性隐藏此方法
E0202: 13,4:Example.aProperty: 一个在test1第26行影响的属性隐藏这个方法

E0202: 7,4:Example.aProperty: An attribute affected in test1 line 26 hide this method
E0202: 13,4:Example.aProperty: An attribute affected in test1 line 26 hide this method

推荐答案

参见 http://www.logilab.org/ticket/89092,一个补丁很快就会被集成到pylint中来修复这个pb

see http://www.logilab.org/ticket/89092, a patch will soon be integrated into pylint to fix this pb

这篇关于Pylint E0202 误报?还是这段代码有问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆