status of Programming by Contract (PEP 316)?

Alex Martelli aleax at mac.com
Sat Sep 1 21:51:15 EDT 2007


Russ <uymqlp502 at sneakemail.com> wrote:
   ...
> > > the inputs. To test the
> > > post-conditions, you just need a call at the bottom of the function,
> > > just before the return,
   ...
> > there's nothing to stop you putting the calls before every return.
> 
> Oops! I didn't think of that. The idea of putting one before every
> return certainly doesn't appeal to me. So much for that idea.

try:
  blah blah with as many return statements as you want
finally:
  something that gets executed unconditionally at the end

You'll need some convention such as "all the return statements are of
the same form ``return result''" (where the result may be computed
differently each time), but that's no different from the conventions you
need anyway to express such things as ``the value that foobar had at the
time the function was called''.


Alex



More information about the Python-list mailing list