[issue9220] Modules no longer usable as context managers

Jim Fulton report at bugs.python.org
Sat Jul 10 21:52:30 CEST 2010


New submission from Jim Fulton <jim at 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: pass
    ... 
    enter ()
    exit (None, None, None)

In Python 2.7:

    >>> import t
    >>> with t: pass
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: __exit__

----------
components: Interpreter Core
messages: 109920
nosy: j1m
priority: normal
severity: normal
status: open
title: Modules no longer usable as context managers
type: behavior
versions: Python 2.7

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


More information about the Python-bugs-list mailing list