[Python-3000] __special__ attrs looked up on the type, not instance

Nick Coghlan ncoghlan at gmail.com
Wed Mar 14 12:14:00 CET 2007


Neal Norwitz wrote:
> [Georg]
> This is modeled after the principle that for new-style objects, __special__
> methods are looked up on the type, not the instance.
> 
> -----
> 
> 1) I didn't remember this, do we have it documented somewhere?
> 2) Assuming #1 is correct, is this rule consistently applied?
> 3) How does (should) this affect 2.6 and migration to 3.0, if at all?

The principle isn't consistently applied - the with statement generates 
standard GET_ATTR opcodes, so it checks the instance first when looking 
for __enter__ and __exit__.

It was questioned at the time, and Guido was OK with it - I believe his 
position was that defining special methods on instances may or may not 
affect behaviour, and whether or not it does so is implementation dependent.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list