Possible PEP: Improve classmethod/staticmethod syntax

Bernhard Herzog bh at intevation.de
Wed Jun 4 18:27:21 CEST 2003


Skip Montanaro <skip at pobox.com> writes:

> To
> use lists there you have to extend list constructor syntax somehow, as I
> used in my original message:
> 
>     def foo(...) [pre=foo_pre, post=foo_post]:
>         <normal code here>

Not really. You could just do it like this:

    def foo(...) [pre(foo_pre), post(foo_post)]:
        <normal code here>

pre and post would be functions that take a function implementing the
pre or postcondition and return a function that when called with a
function object add the pre/post condition to the function. E.g. 

def pre(precondition):
    def install_pre_condition(function):
        def call_with_precondition(*args, **kw):
            precondition(*args, **kw)  # or however the precondition is called
            return function(*args, **kw)
        return call_with_precondition
    return install_pre_condition


   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/




More information about the Python-list mailing list