mfenniak / pg8000

A Pure-Python PostgreSQL Driver
http://pythonhosted.org/pg8000/
Other
222 stars 55 forks source link

Add Python 'with' keyword support for the Connection object #171

Closed seushermsft closed 5 years ago

seushermsft commented 5 years ago

This allows developers to use:

with pg8000.connect(**db_connect) as db:

instead of using a try-finally mechanism with extra checking to ensure they don't attempt to call close on an uninitialized object.

seushermsft commented 5 years ago

This fixes #170

I am hitting issues running test cases (even unaltered) on my machine, but my application code runs correctly with this change.

tlocke commented 5 years ago

Thanks @seushermsft , I've used this patch at https://github.com/tlocke/pg8000/commit/ecdc956f053351efb3ce806abd822ff7675a61a8 and https://github.com/tlocke/pg8000/commit/33f579291abd4088bae4c8dccd13d27ac38efdc7