Is there any stylistic taboo or other downside to implementing trivial methods by assignment to class attributes? E.g. like bar and baz below, as opposed to the more ususal foo.
class MyClass(object):
def hello(self):
return 'hello'
def foo(self):
return self.hello()
bar = lambda self: self.hello()
baz = hello
I find myself tempted by the apparent economy of things like this:
__str__ = __repr__ = hello
Personally, I think things like
are fine, but
is evil. You cannot easily give a lambda a docstring, and the
.func_nameattribute will have the meaningless value<lambda>. Both those problems don’t occur for the first line.