This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients lemburg
Date 2013-02-21.16:31:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1361464311.73.0.77004817262.issue17268@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-02-21 16:31:51lemburgsetrecipients: + lemburg
2013-02-21 16:31:51lemburgsetmessageid: <1361464311.73.0.77004817262.issue17268@psf.upfronthosting.co.za>
2013-02-21 16:31:51lemburglinkissue17268 messages
2013-02-21 16:31:51lemburgcreate