> My own preference would be: > > def foo(x): > if x >= 0: > return math.sqrt(x) > return None
Kind of getting into the weeds here, but I would always invert this to "return errors early, and keep the normal flow at the main indentation level". Depends a little on what foo() means, but it seems to me the "return None" case is the exceptional/error case, so this would be: def foo(x): if x < 0: return None return math.sqrt(x) The handling of errors is done first, and the normal case stays at the main indentation level. Is this discussed in style guides at all? I don't see anything directly in PEP 8, but I might be missing something. Oh wait, I just noticed this is exactly how Guido has it in his PEP addition with the definition of bar(). :-| -Ben _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com