On Tue, Oct 25, 2011 at 03:32:28PM +0200, Michael Hanselmann wrote: > Am 25. Oktober 2011 10:18 schrieb Iustin Pop <[email protected]>: > > My questions is whether we need to "generate" code at all, instead of > > parsing the descriptor tables and doing the serialisation at run time, > > e.g.: > > […] > > Short version: it is possible, but makes debugging harder and the code > difficult to understand. My proposal is to proceed with the generated > code and change if and when we find an acceptable solution. > > As discussed we would have to override the normal case at least for > “test_delay”, and possibly others as well. To test this I defined two > classes (only representing the bare minimum here): > > class TestRunnerBase(object): > def __getattr__(self, name): > … > > class TestRunner(TestRunnerBase): > def call_test_delay(self, *args): > return TestRunnerBase.call_test_delay(self, *args) > > When trying to call “call_test_delay” on the derived class it fails > with “'TestRunnerBase' has no attribute 'call_test_delay'”. The reason > is that the function is actually only available on instances of > TestRunnerBase, not on the class itself (as used here). There are two > ways around this: > > - Define “getattr” in a metaclasses: This will be tricky with > bound/unbound methods. I specifically wanted to avoid using > metaclasses as they lead to magic. > - Call base class' “__getattr__” explicitely: > TestRunnerBase.__getattr__(self, "call_test_delay")…. While it works, > it's not nice. > > Therefore I'd rather proceed with code generated at build time for > now, which behaves like any other standard Python code at runtime. > There is no magic involved.
I believe this is doable in a simple way without having to generate code, but I don't have the time now to argue for it. Let's go with this version for now. I'll continue reviewing your patches as they are now. thanks, iustin
