[New-bugs-announce] [issue17268] Context managers written as C types no longer work in Python 2.7
Marc-Andre Lemburg
report at bugs.python.org
Thu Feb 21 17:31:51 CET 2013
New submission from Marc-Andre Lemburg:
We have implemented the context manager API for connections and cursors in our mxODBC module and this works fine in Python 2.6.
In Python 2.7 we get the following error:
Traceback (most recent call last):
File "context-manager.py", line 6, in <module>
with db.cursor() as cursor:
AttributeError: __exit__
Here's the code snippet:
import mx.ODBC.unixODBC as ODBC
connectionString = '...'
db = ODBC.DriverConnect(connectionString)
with db.cursor() as cursor:
print cursor
The mxODBC cursor is not an instance, it's implemented as Python type in C. It implements the tp_getattr slot, but not the tp_desc_get slot.
Looking at the apparently new API _PyObject_LookupSpecial(), this does not appear to support the tp_getattr slot and goes straight for the tp_desc_get slot.
----------
messages: 182598
nosy: lemburg
priority: normal
severity: normal
status: open
title: Context managers written as C types no longer work in Python 2.7
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17268>
_______________________________________
More information about the New-bugs-announce
mailing list