[Python-checkins] r73326 - python/trunk/Doc/whatsnew/2.7.rst

R. David Murray rdmurray at bitdance.com
Wed Jun 10 15:56:58 CEST 2009


On Wed, 10 Jun 2009 at 21:45, Nick Coghlan wrote:

> amaury.forgeotdarc wrote:
>> Modified: python/trunk/Doc/whatsnew/2.7.rst
>> ==============================================================================
>> --- python/trunk/Doc/whatsnew/2.7.rst	(original)
>> +++ python/trunk/Doc/whatsnew/2.7.rst	Wed Jun 10 01:18:50 2009
>> @@ -672,7 +672,7 @@
>>  * Because of an optimization for the :keyword:`with` statement, the special
>>    methods :meth:`__enter__` and :meth:`__exit__` must belong to the object's
>>    type, and cannot be directly attached to the object's instance.  This
>> -  affects new-styles classes (derived from :class:`object`) or C extension
>> +  affects new-styles classes (derived from :class:`object`) and C extension
>                      ^
>
> And to round out tonight's trio of typos, an unintended 's' here.

Unless I'm remembering wrong, the introduction of the with opcode was
actually done _so that_ __enter__ and __exit__ would be looked up only
on the object's type.  That is, the cause and effect implied by your
statement is the reverse of what happened, Amaury :).  The optimization
was a side benefit.

The reason this was done, IIUC, is that at some point Guido decreed that
all special methods should be looked up on the type, and Benjamin went
through the code base and made that consistently true.  There are several
other special methods for which this changed in 3.1, not just __enter__
and __exit__.  You'd have to check the commit logs or talk to Benjamin
for a list.

--David


More information about the Python-checkins mailing list