New submission from Jim Fulton j...@zope.com:
In python 2.7 a module can't be used as a context manager.
For example, given the module, t.py:
def __enter__(*args):
print 'enter', args
def __exit__(*args):
print 'exit', args
In Python 2.6:
import t
with t:
Éric Araujo mer...@netwok.org added the comment:
IIUC, magic methods are looked up on the object’s class, not in the object’s
__dict__. This behavior in 2.6 seems like a bug to me.
I-tried-to-add-__call__-to-a-module-once-ly yours
--
nosy: +merwok
Éric Araujo mer...@netwok.org added the comment:
Confirmed: http://docs.python.org/reference/datamodel#specialnames
Closing. Sorry! (BTW, using import hackery and a custom module type, you could
achieve your goal.)
--
resolution: - invalid
stage: - committed/rejected
status: open -
Mark Dickinson dicki...@gmail.com added the comment:
Just for the record, this changed with the introduction of the SETUP_WITH
opcode in r72912. Perhaps Benjamin can confirm that the behaviour change was
deliberate?
--
nosy: +benjamin.peterson, mark.dickinson
Benjamin Peterson benja...@python.org added the comment:
Yes, definitely.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9220
___
___
Jim Fulton j...@zope.com added the comment:
On Sat, Jul 10, 2010 at 4:08 PM, Éric Araujo rep...@bugs.python.org wrote:
Éric Araujo mer...@netwok.org added the comment:
Confirmed: http://docs.python.org/reference/datamodel#specialnames
Closing. Sorry! (BTW, using import hackery and a custom