[Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.

Joel Bender jjb5 at cornell.edu
Thu May 10 18:23:11 CEST 2007


>      @before(do_stuff)
>      def debug_it(ob: ClassC):
>          import pdb
>          pdb.set_trace()

This is probably far fetched, but I would much rather see:

       before do_stuff(ob: ClassC):
           import pbd
           pdb.set_trace()

So the keyword 'before' and 'after' are just like 'def', they define 
functions with a particular signature that get inserted into the "which 
function to call" execution sequence.

I would want to be able to reference functions within classes as well:

       >>> class A:
       ...     def f(self, x):
       ...         print 'A.f, x =', x
       ...
       >>> z = A()
       >>> z.f(1)
       A.f, x = 1
       >>>
       >>> before A.f(self, x):
       ...     print 'yo!'
       ...
       >>> z.f(2)
       yo!
       A.f, x = 2

Could the sequence of opcodes for the 'before f()' get mushed into the 
front of the existing code for f()?  That would mean that changes to 'x' 
would be reflected in the original f():

       >>> before A.f(self, x):
       ...     print 'doubled'
       ...     x = x * 2
       >>> z.f(3)
       doubled
       yo!
       A.f, x = 6

And does a 'return' statement from a before short-circuit the call, or 
should it mean the same thing as falling off the end?


Joel


More information about the Python-3000 mailing list