[Python-Dev] PEP 447: hooking into super() attribute resolution

Guido van Rossum guido at python.org
Mon Jul 15 19:14:10 CEST 2013


On Mon, Jul 15, 2013 at 9:56 AM, Ronald Oussoren <ronaldoussoren at mac.com> wrote:
>
> On 15 Jul, 2013, at 18:49, Guido van Rossum <guido at python.org> wrote:
>>
>>
>>> A major open issue: the __locallookup__ method could also be used for normal attribute resolution, but that probably causes issues with attribute caching (see the PEP for details).  I haven't worked out yet if it is worthwhile to tweak the proposal to fix the caching issues (even though the proposal currently says that PyObject_GenericGetAttr will use the new method). Fixing the caching issue definitly would help in my primary use case by reducing code duplication, but might end up making the API unnecessarily complex.
>>
>> Hm. It looks like the functionality you actually want to hook into is
>> in _PyType_Lookup().
>
> That's right. I didn't want to get too technical, but forgot to consider
> who are reading this :-)

Heh. :-)

>> I think that in this case the PEP's acceptance will be highly
>> correlated with your ability to produce an actual patch that (a)
>> implements exactly the functionality you want (never mind whether it
>> matches the exact API currently proposed), and (b) doesn't slow down
>> classes that don't provide this hook.
>
> I'd only reall need the functional change to super(), but I am working on
> a patch that also changes _PyType_Lookup. I think I can avoid slowdown
> by making the tp_locallookup optional and only "punishing" those classes
> that use the new slot.  A minor complication is that I'll have to change
> the interface of _PyType_Lookup, it currently returns a borrowed reference
> and will return a new reference. That's just careful bookkeeping though.

Hm. That sounds scary. I'd rename it, because this is actually an
important (and scary) signature change, that type checkers otherwise
won't see. Don't trust that you can find all call sites (there may be
some in 3rd party code even though it starts with _). You don't want
to suddenly start causing leaks all over the place.

FWIW I agree that the change should affect _PyType_Lookup, because it
would be very surprising if super() used a different override than
regular attribute lookup.

>> Other than that, I think that it's a laudable attempt at generalizing,
>> and I hope you solve the implementation conundrum.
>
> I was pleasantly surprised in how the changed API was cleaner and applicable
> to _PyType_Lookup as well. I guess that means I'm on the right path.

There's a Zen of Python line about that. :-)

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list