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 <[email protected]>
<http://bugs.python.org/issue17268>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com