"Phil Thompson" <phil@riverbankcomputing.co.uk> writes:
Questions...
1. What is the reason why it doesn't go via tp_getattro?
Because it wouldn't work if it did? I'm not sure what you're suggesting here.
I'm asking for an explanation for the current implementation. Why wouldn't it work if it got the attribute via tp_getattro?
Well, using type->tp_getattro is just different to looking in tp_dict -- it finds metamethods, for example. Hmm. Well, I'm fairly sure there is a difference, I'm not sure I can explain it right now :(
2. A possible workaround is to subvert the ma_lookup function of the type dictionary after creating the type to do something similar to what my tp_getattro function is doing.
[...]
Yes, having looked in more detail at the dict implementation I really don't want to go there.
Good :)
4. Am I missing a more correct/obvious technique? (There is no need to support classic classes.)
Hum, I can't think of one, I'm afraid.
There has been some vague talk of having a tp_lookup slot in typeobjects, so
PyDict_GetItem(t->tp_dict, x);
would become
t->tp_lookup(x);
(well, ish, it might make more sense to only do that if the dict lookup fails).
That would be perfect. I can't Google any reference to a discussion - can you point me at something?
Well, most of the discussion so far has been in my head :) There was a little talk of it in the thread "can we stop pretending _PyType_Lookup is internal" here and possibly on pyobjc-dev around the same time. I'm not that likely to work on it soon -- I have enough moderately complex patches to core Python I'm persuading people to think about :-/.
For now, not being lazy seems your only option :-/ (it's what PyObjC does).
Not practical I'm afraid. I think I can only document that super doesn't work in this context.
Oh well. I can't even think of a way to make it fail reliably... Cheers, mwh -- Java sucks. [...] Java on TV set top boxes will suck so hard it might well inhale people from off their sofa until their heads get wedged in the card slots. --- Jon Rabone, ucam.chat