【发布时间】:2012-09-15 19:41:40
【问题描述】:
Pyflakes 不能很好地处理以下代码:
@property
def nodes(self):
return self._nodes
@nodes.setter
def nodes(self, nodes):
"""
set the nodes on this object.
"""
assert nodes != [] # without nodes no route..
self.node_names = [node.name for node in nodes]
self._nodes = nodes
使用使用 pyflakes 的 vim 和 syntastic 我得到以下错误:
W806 redefinition of function 'nodes' from line 5
所以我收到关于 @nodes.setter 的警告,因为我重新定义了 nodes。
既然这段代码是正确的,我该如何禁用这个无用的警告?或者哪个 python 检查器能正确处理这段代码?
更新
我在重构代码时遇到了一些问题,因为属性和函数具有不同的继承行为。访问基类的属性是不同的。见:
- How to call a property of the base class if this property is being overwritten in the derived class?。
- Python derived class and base class attributes?
所以我现在倾向于避免使用这种语法并改用适当的函数。
【问题讨论】:
标签: python properties decorator python-decorators pyflakes