pylint bug - E1101 & E0102使用@property + @foo.setter

时间:2022-05-24 16:45:55

I noticed pylint doesn't handle well the case of:

我注意到pylint处理不好:

@property
def foo(self):
   return self._bar.foo

@foo.setter
def foo(self, foo_val):
   self._bar.foo = foo_val

Though it's a perfectly valid case syntax since python2.6

虽然它是一个完全有效的case语法,因为python2.6

It says I defined foo twice, and doesn't understand the ".setter" syntax (Gives E1101 & E0102).

它说我定义了两次foo,不理解"setter语法(给出E1101和E0102)。

Is there a workaround for that without having to change the code? I don't want to disable the errors as they are important for other places.

在不需要修改代码的情况下,是否有解决方案?我不想禁用这些错误,因为它们对其他地方很重要。

Is there any other tool I can use that handles it better? I already checked pyflakes and it behaves the same way. PyDev's code analysis seems to handle this specific case better, but it doesn't check for conventions, refactoring, and other cool features pylint does, and I can't run it from an external script (or can I??)

我还能用其他工具更好地处理它吗?我已经检查过pyflakes,它的行为也是一样的。PyDev的代码分析似乎更好地处理了这个特定的情况,但是它没有检查惯例、重构和pylint所做的其他很酷的特性,而且我不能从外部脚本(或者我可以吗?)

Thanks!

谢谢!

4 个解决方案

#1


2  

This is ticket http://www.logilab.org/ticket/51222 on the pylint project. Monitor it's status.

这是pylint项目的票证http://www.logilab.org/ticket/51222。监控它的地位。

#2


4  

If you don't want to disable the errors globally, you can disable them for these specific lines, for example:

如果您不想在全局上禁用这些错误,您可以禁用这些错误,例如:

def foo(self, foo_val): # pylint: disable-msg=E0102

#3


1  

Huh. Annoying. And all the major tools I could find (pyflakes, pylint, pychecker) exhibit this problem. It looks like the problem starts in the byte code, but I can't get dis to give me any byte code for object properties.

嗯。烦人。我能找到的所有主要工具(pyflakes, pylint, pychecker)都显示出这个问题。看起来问题是从字节代码开始的,但是我不能让dis给我任何对象属性的字节代码。

It looks like you would be better off if you used this syntax:

如果你使用这种语法,看起来你会过得更好:

# Changed to longer member names to reduce pylint grousing
class HughClass(object):
    def __init__(self, init_value):
        self._hugh = init_value
    def hugh_setter(self):
        return self._hugh * 2
    def hugh_getter(self, value):
        self._hugh = value / 2
    hugh = property(hugh_getter, hugh_setter)

Here's a nice blog article on it. LOL-quote:

这里有一篇关于它的不错的博客文章。LOL-quote:

Getters and setters belong to the sad world of Java and C++.

Getters和setters属于Java和c++的悲伤世界。

#4


0  

This was reported as a bug in pyflakes, and it appears to be fixed in current trunk. So I guess the answer (now) is: pyflakes!

这在pyflakes中被报告为一个bug,并且看起来在当前的trunk中得到了修复。所以我猜现在的答案是:pyflakes!

#1


2  

This is ticket http://www.logilab.org/ticket/51222 on the pylint project. Monitor it's status.

这是pylint项目的票证http://www.logilab.org/ticket/51222。监控它的地位。

#2


4  

If you don't want to disable the errors globally, you can disable them for these specific lines, for example:

如果您不想在全局上禁用这些错误,您可以禁用这些错误,例如:

def foo(self, foo_val): # pylint: disable-msg=E0102

#3


1  

Huh. Annoying. And all the major tools I could find (pyflakes, pylint, pychecker) exhibit this problem. It looks like the problem starts in the byte code, but I can't get dis to give me any byte code for object properties.

嗯。烦人。我能找到的所有主要工具(pyflakes, pylint, pychecker)都显示出这个问题。看起来问题是从字节代码开始的,但是我不能让dis给我任何对象属性的字节代码。

It looks like you would be better off if you used this syntax:

如果你使用这种语法,看起来你会过得更好:

# Changed to longer member names to reduce pylint grousing
class HughClass(object):
    def __init__(self, init_value):
        self._hugh = init_value
    def hugh_setter(self):
        return self._hugh * 2
    def hugh_getter(self, value):
        self._hugh = value / 2
    hugh = property(hugh_getter, hugh_setter)

Here's a nice blog article on it. LOL-quote:

这里有一篇关于它的不错的博客文章。LOL-quote:

Getters and setters belong to the sad world of Java and C++.

Getters和setters属于Java和c++的悲伤世界。

#4


0  

This was reported as a bug in pyflakes, and it appears to be fixed in current trunk. So I guess the answer (now) is: pyflakes!

这在pyflakes中被报告为一个bug,并且看起来在当前的trunk中得到了修复。所以我猜现在的答案是:pyflakes!