[Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc. (original) (raw)
Joel Bender jjb5 at cornell.edu
Thu May 10 18:23:11 CEST 2007
- Previous message: [Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
- Next message: [Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
@before(dostuff) def debugit(ob: ClassC): import pdb pdb.settrace()
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 = 2Could 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 = 6And does a 'return' statement from a before short-circuit the call, or should it mean the same thing as falling off the end?
Joel
- Previous message: [Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
- Next message: [Python-3000] PEP 3124 - Overloading, Generic Functions, Interfaces, etc.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]