I might be wrong, but this looks like a job for the ||= operator.
def get_foo(): return self._foo |= Bar() My Perl is rusty at best, but ||= seems to return an R-value, so the return should work.
Edit: Woopsie, this is Python. It doesn't have a ||=. Bummer.
Then I'd use the simulated ternary operator:
def get_foo() self._foo = self._foo ==is None and Bar() or self._foo return self._foo Edit 2: Python has a real ternary operator. Use it instead of the above.
def get_foo() self._foo = Bar() if self._foo ==is None else self._foo return self._foo