Alex Rivera | Logout

fix pyflakes dealing with @property setter decorator

Asked 2012-09-24T10:48:47.450
11

Pyflakes does not deal very well with the following code:

@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

Using vim and syntastic which uses pyflakes I get the following error:

    W806 redefinition of function 'nodes' from line 5

So I get warnings about @nodes.setter because I redefine nodes.

How do I disable this useless warning since this code is correct? Or which python checker deals with this code correctly?

Update

I ran into some problems when I refactored my code because properties and functions have different inheritance behavior. Accessing properties of a base class is different. see:

so I now tend to avoid this syntax and use proper functions instead.

Edit
Report

1 Answer

3

Various fixes that might be released at some point:

The last seems closest to release, as divmod is the parent project for PyFlakes.

Other than patching the package yourself, you could always work around the issue:

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

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

Unfortunately, this will result in pollution of the class namespace.

answered 2012-09-24T11:08:32.910

Your Answer