monkey patching __code__
Sven R. Kunze
srkunze at mail.de
Wed Mar 23 18:06:01 EDT 2016
On 23.03.2016 09:24, dieter wrote:
> But you have observed that you cannot do everything with a
> code substitution: a function call does not only depend on the code
> but also on other properties of the function object: e.g. the
> parameter processing.
Yep, that's because Python is very flexible and provides means for
changing even that. So, it's not part of the __code__ object but part of
the actual function. That's okay.
> You might be able to change them in a similar way as "__code__" (i.e.
> direct modification). Otherwise, you would need to construct a new
> "function object" -- and lose the possibility to completely
> change the function object in place.
Exactly. Except __globals__ we are all set and I think that'll work for
us. I will report once we've implemented it that way.
Best,
Sven
More information about the Python-list
mailing list