Pregunta

Me pylint notado no maneja bien el caso de:

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

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

A pesar de que es una sintaxis caso perfectamente válida desde python2.6

Se dice que definí foo dos veces, y no entiende la sintaxis ".setter" (Da E1101 y E0102).

¿Hay una solución para que, sin tener que cambiar el código? No quiero desactivar los errores ya que son importantes para otros lugares.

¿Hay alguna otra herramienta que puede utilizar que maneja mejor? Ya revisé pyflakes y se comporta de la misma manera. análisis de código de PyDev parece manejar este caso específico, mejor, pero no comprueba para convenciones, refactorización, y cuenta con otra fría pylint hace, y no puedo ejecutarlo desde un script externo (o puedo ??)

Gracias!

¿Fue útil?

Solución

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

Otros consejos

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

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++.

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!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top