Éric Araujo mer...@netwok.org added the comment:
After a quick perusal of the PEP, there are no wrong definitions of context
managers (IOW they define methods in a class, not attribute on an object), but
the pseudo-code explaining how the statement works use things like
“mgr.__enter__”
benrg benrud...@gmail.com added the comment:
But when I translate my example according to PEP 343, it works (i.e., doesn't
raise an exception) in 3.2, and PEP 343 says [t]he details of the above
translation are intended to prescribe the exact semantics. So I think that at
least one of PEP
Changes by Georg Brandl ge...@python.org:
--
assignee: - benjamin.peterson
nosy: +benjamin.peterson
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11428
___
Benjamin Peterson benja...@python.org added the comment:
Well, the pep is wrong, too.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11428
___
New submission from benrg benrud...@gmail.com:
class MakeContextHandler:
def __init__(self, enter, exit):
self.__enter__ = enter
self.__exit__ = exit
with MakeContextHandler(lambda: None, lambda *e: None): pass
In 3.1.3 this worked; in 3.2 it raises AttributeError('__exit__'), which
Georg Brandl ge...@python.org added the comment:
The bug is actually in 3.1 and fixed in 3.2: special methods (those with
__underscore__ names) are supposed to be looked up on the class, not the
instance.
--
nosy: +georg.brandl
resolution: - invalid
status: open - closed