Returning none

Michael P. Reilly arcege at shore.net
Mon Aug 30 16:02:49 EDT 1999


Magnus L. Hetland <mlh at idt.ntnu.no> wrote:
: Skip Montanaro <skip at mojam.com> writes:

:>     Jeff> I think this proposal would break too much existing code, even for
:>     Jeff> a Python 2 change.
: [...]
:> 
:> How about a compromise?  Perhaps Aaron Watters' PyLint can be modified to
:> bitch about functions without a return as the last statement?

: Well... That would be a bit to strict, wouldn't it? As long as you
: don't use the return value, there's no point in returning anything...
: So what it probably *should* do, is argue when you assign the return
: value of a function without a return as a last statement to a
: variable... But that isn't possible, of course, since functions can be
: assigned dynamically.

: And - it might not even be true that it should be the last statement.
: The return value might only be used in situations where the functions
: returns a value earlier in its body...

: So - this seems difficult to me. Only solution is a runtime error -
: which would, of course, break a lot of code.

I do not even agree that returning None is an error.  From a language
semantic point of view, a function is a expression and so must return
something (even implicitly), unless an explicit exception is raised.
Other languages do not take this view (and in those "functions" are not
always expression elements), but Python has tried to be consistant in
this respect.  I.e. no "procedure vs. function" distinction, just an
"exec vs. eval" distinction, which is more on the syntax not the
semantics.

  -Arcege





More information about the Python-list mailing list