Description
By returning a cursor rather than a connection, extra code needs to be written to handle exceptions and close the connection. Why not return a connection object, then a user can use a second nested with to get a cursor object. This way, wherever an error occurs, the cursors/connections will be neatly closed, and tracebacks will nicely propagate.
I noticed this was a problem when using SSH, and the tunnel wasn't getting decommissioned because the DB connection was still active. Other users also having this problem:
https://stackoverflow.com/questions/31214658/can-i-use-pymysql-connect-with-with-statement
Relevant lines in the code:
PyMySQL/pymysql/connections.py
Line 494 in 09040ab
PyMySQL/pymysql/connections.py
Line 498 in 09040ab