status of Programming by Contract (PEP 316)?

Russ uymqlp502 at sneakemail.com
Thu Aug 30 19:37:30 EDT 2007


Bruno Desthuilliers wrote:
> Russ a écrit :
> (snip)
>
> > I don't see how you can avoid adding some new syntax, given that
> > Python does not
> > currently have syntax for specifying invariants and pre- and post-
> > conditions.
>
> class Parrot(object):
>    @pre(lambda x : x != 42)
>    @post(lambda result: result != 42)
>    @invariant(lambda self: self.x == 42)
>    def reliable_method(self, x):
>      # your code here
>      return something

That looks like new syntax to me. Did I miss your point?

I have no strong leaning about what the exact syntax should be for
programming by contract.
The syntax you show above seems reasonable, except that I am not sure
about requiring
that everything be put inside parentheses. That seems a bit confining
for more complex
conditions.




More information about the Python-list mailing list