[New-bugs-announce] [issue12022] 'transaction' module-as-context-manager thwarted by Python 2.7.1
report at bugs.python.org
Fri May 6 22:07:22 CEST 2011
New submission from Daniel Holth <dholth at fastmail.fm>:
"How much do we care about special method lookup?" Python recently bypasses __getattr__ entirely when looking up context managers. http://mail.python.org/pipermail/python-dev/2009-May/089535.html
Could this be the reason that ZODB's transaction module, which attempts to be a context manager by declaring
manager = ThreadTransactionManager()
__enter__ = manager.get
__exit__ = manager.__exit__
Does not work in Python 2.7.1 on Ubuntu 11.04 or RHEL5? Frustratingly, the exception is no more specific than an AttributeError, even though hasattr(transaction, '__exit__')?
I would prefer to never get AttributeError: transaction.__exit__ when hasattr(transaction, '__exit__') as I find that to be very confusing. Maybe the interpreter could raise SpecialAttributeError('transaction.__exit__ is not sufficiently special') instead.
components: Interpreter Core
title: 'transaction' module-as-context-manager thwarted by Python 2.7.1
versions: Python 2.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce