[issue20149] 'with instance' references class's __enter__ attribute rather than instance's

R. David Murray report at bugs.python.org
Mon Jan 6 20:44:25 CET 2014


R. David Murray added the comment:

"magic methods" like __enter__ and __exit__ are only looked up on the class, not on the instance.  This is by design.

In some older versions of Python some specific methods (and I think __enter__ and __exit__ were among them for a time) were looked up on the instances, but this was a bug.

(Personally I think it would be nice if they were looked up on the instances, but there are good reasons why this is not done.)

----------
nosy: +r.david.murray
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20149>
_______________________________________


More information about the Python-bugs-list mailing list