Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 修复处理@property setter decorator的pyflakes_Python_Properties_Decorator_Python Decorators_Pyflakes - Fatal编程技术网

Python 修复处理@property setter decorator的pyflakes

Python 修复处理@property setter decorator的pyflakes,python,properties,decorator,python-decorators,pyflakes,Python,Properties,Decorator,Python Decorators,Pyflakes,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 n

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
使用vim和使用pyflakes的syntastic,我得到以下错误:

    W806 redefinition of function 'nodes' from line 5
所以我得到了关于
@nodes.setter
的警告,因为我重新定义了
节点

既然此代码正确,如何禁用此无用警告?或者哪个python检查器正确地处理了这些代码

更新

我在重构代码时遇到了一些问题,因为属性和函数具有不同的继承行为。访问基类的属性是不同的。见:


因此,我现在倾向于避免使用这种语法,而是使用适当的函数。

pyflakes问题跟踪器上有一个关于这个问题的补丁;您可以安装或手动应用修补程序。

可能在某个时间发布的各种修复程序:

最后一个似乎离发布最近,因为divmod是PyFlakes的父项目

除了自己修补软件包外,您还可以随时解决此问题:

@property
def nodes(self):
    return self._nodes

@nodes.setter
def _nodes_setter(self, nodes):    # FIXME: pyflakes
    ...

不幸的是,这将导致类名称空间的污染。

我遇到了同样的问题,为了有效地抑制这个特定的实例,我在添加decorator的行的末尾添加了#NOQA行。在这种情况下,它应该看起来像

@nose.setter  #  NOQA 
这为我解决了问题。这并不理想,但对我的需要来说已经足够了


这样做不是为了抑制所有W806警告,而是为了捕捉可能需要修复的其他实例

如果应用这些“修复”,则我的代码将中断,因为我在
对象的位置使用了override
\uuuuuu setattr\uuuuuuu
。如果我重命名setters方法,则我进行的调用将失败。它找不到nodes方法。您不能使用
del\u nodes\u setter