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

发布于 2024-09-28 22:32:51 字数 460 浏览 0 评论 0原文

我注意到 pylint 不能很好地处理以下情况:

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

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

尽管它是自 python2.6 以来完全有效的 case 语法

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

有没有无需更改代码的解决方法?我不想禁用这些错误,因为它们对其他地方很重要。

我可以使用其他工具来更好地处理它吗?我已经检查过 pyflakes,它的行为方式相同。 PyDev 的代码分析似乎可以更好地处理这种特定情况,但它不会检查约定、重构和 pylint 所做的其他很酷的功能,而且我无法从外部脚本运行它(或者我可以吗?)

谢谢!

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

@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

It says I defined foo twice, and doesn't understand the ".setter" syntax (Gives 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??)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爱*していゐ 2024-10-05 22:32:51

如果您不想全局禁用错误,则可以针对这些特定行禁用它们,例如:

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

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
破晓 2024-10-05 22:32:51

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

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

白龙吟 2024-10-05 22:32:51

呵呵。恼人的。我能找到的所有主要工具(pyflakes、pylint、pychecker)都存在这个问题。看起来问题是从字节码开始的,但我无法让 dis 为我提供对象属性的任何字节码。

如果您使用以下语法,您的情况似乎会更好:

# 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)

这是 不错的博客文章。哈哈-引用:

吸气剂和吸气剂属于悲伤者
Java 和 C++ 的世界。

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.

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:

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

囍孤女 2024-10-05 22:32:51

这是报告为 pyflakes 中的错误,并且似乎已在当前主干中修复。所以我猜答案(现在)是:pyflakes!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文