This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bethard
Recipients
Date 2007-04-03.22:01:13
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
This is not true for all __special__ methods, e.g. __enter__ and __exit__:

>>> class C(object):
...     pass
...    
>>> def enter(*args):
...     print 'enter', args
...     
>>> def exit(*args):
...     print 'exit', args
...     
>>> c = C()
>>> c.__enter__ = enter
>>> c.__exit__ = exit
>>> with c:
...     print 'hi'
...     
enter ()
hi
exit (None, None, None)

The documentation should say something like "When interpreting syntax that invokes a __special__ method, Python looks for the __special__ method on the instance's class. As an implementation detail, the lookup for some __special__ methods may also check the instance first, but this behavior should not be relied upon." This should probably go into the Reference Manual section 3.4: http://docs.python.org/ref/specialnames.html
History
Date User Action Args
2007-08-23 14:52:39adminlinkissue1684991 messages
2007-08-23 14:52:39admincreate