[Python-3000] PEP Parade (original) (raw)

Samuele Pedroni pedronis at openendsystems.com
Tue May 1 22:34:58 CEST 2007


For what is worth changing func_code is supported both by PyPy and Jython. What cannot be done in Jython is construct a code object out of a string of CPython bytecode, but it can be extracted from other functions.

Jython 2.2b1 on java1.5.0_07 Type "copyright", "credits" or "license" for more information.

def f(): ... return 1 ... f() 1 def g(): ... return 2 ... f.func_code = g.func_code f() 2

Phillip J. Eby wrote:

At 12:14 PM 5/1/2007 -0700, Guido van Rossum wrote:

Suppose you couldn't assign to class of a function (that's too messy to deal with in CPython) and you couldn't assign to its code either. What proposed functionality would you lose?

The ability to overload any function, without having to track down all the places it's already been imported or otherwise saved, and change them to point to a new function or a non-function object.

How would you ideally implement that functionality if you had the ability to modify CPython in other ways? (I'm guessing you'd want to add some functionality to function objects; what would that functionality have to do?) Hm... well, in PyPy they have a "become" feature (I don't know if it's a mainline feature or not) that allows you to say, "replace object A with object B, wherever A is currently referenced". Then the replacement object (GF implementation) needn't even be a function. A narrower feature, however, more specific to functions, would just be some way to redirect or guard the function's actual execution. For example, if function objects had a writable call attribute, that would be invoked in place of the normal behavior. (Assuming there was a way to save the old call or make a copy of the function before it was modified.) I really just need a way to make calling the function do something different from what it normally would -- and ideally this should be in such a way that I could still invoke the function's original behavior. (So it can be used as the default method when nothing else matches, or the least-specific fallback method.)


Python-3000 mailing list Python-3000 at python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/pedronis%40openendsystems.com



More information about the Python-3000 mailing list