python_api icon indicating copy to clipboard operation
python_api copied to clipboard

"return self" statements

Open zopyx opened this issue 9 years ago • 3 comments

The whole codebase contains tons of

return self

lines.

This is completely unpythonic and they do not make any sense. Just omit the 'return' statement completely..

zopyx avatar Feb 16 '16 14:02 zopyx

+1 to this!

xquery avatar Jun 14 '16 12:06 xquery

So a method with no return statement returns self by default? Ok.

ndw avatar Jun 14 '16 15:06 ndw

A method with 'return' returns implicit None. There is no reason why a getter/setter should return anything at all - in particular why is should return 'self'. In addition: the typical getter/setter pattern of Java is pointless Python. Directly attribute assignment or access is what you want. If you need to massage a value upon get or set: use property()...but only if you really need it.

zopyx avatar Jun 14 '16 15:06 zopyx