On 7 June 2013 06:49, Skip Montanaro <s...@pobox.com> wrote: > If I never refer to self.x or self.y within the class's methods it > would be nice to be alerted. >
+1, and that seems feasible to add to pylint. > > Here's the other problem I'd like to catch: > class X(object): > ... > def get_foo(self): > return self._foo > foo = property(get_foo) > The problem here is that I have violated this Zen of Python dictum: > There should be one-- and preferably only one --obvious way to do it. I will admit that I sometimes go back and forth on property objects. But there is no obvious one way to do this in Python<http://stackoverflow.com/q/6618002/243712>. Depending on your project's standards you could say any of - don't use trivial getters/setters or properties, just have a public field (consenting adults) - don't use properties, use an explicit method call (because calls that may take time or have side effects should not look like a simple attribute read) - don't assign property objects to an attribute, use @property - the property getter implementation shouldn't be public - a property getter implementation that only reads a variable should be an inlined lambda - ... should be an operator.attrgetter (I realize your example of just getting a field value may be unrealistically simplified, but even if the getter was doing a lot of work several of those options are available.) -- Martin
_______________________________________________ code-quality mailing list code-quality@python.org http://mail.python.org/mailman/listinfo/code-quality