From 182a23a28a912f118e8bfb71b88e401efa06c745 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 18 Dec 2018 21:45:15 +0900 Subject: [PATCH 1/2] Remove context manager support from Connection --- pymysql/connections.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index 2e4122b4..af074e21 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -490,20 +490,6 @@ def cursor(self, cursor=None): return cursor(self) return self.cursorclass(self) - def __enter__(self): - """Context manager that returns a Cursor""" - warnings.warn( - "Context manager API of Connection object is deprecated; Use conn.begin()", - DeprecationWarning) - return self.cursor() - - def __exit__(self, exc, value, traceback): - """On successful exit, commit. On exception, rollback""" - if exc: - self.rollback() - else: - self.commit() - # The following methods are INTERNAL USE ONLY (called from Cursor) def query(self, sql, unbuffered=False): # if DEBUG: From fc0d1b57ee4f5b9f5f862b15ddc1c4e7902954d5 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 18 Dec 2018 21:51:53 +0900 Subject: [PATCH 2/2] Remove test for context manager API --- pymysql/tests/test_connection.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/pymysql/tests/test_connection.py b/pymysql/tests/test_connection.py index 7f31f6c2..7c258df8 100644 --- a/pymysql/tests/test_connection.py +++ b/pymysql/tests/test_connection.py @@ -450,27 +450,6 @@ def test_read_default_group(self): ) self.assertTrue(conn.open) - def test_context(self): - with self.assertRaises(ValueError): - c = self.connect() - with pytest.warns(DeprecationWarning): - with c as cur: - cur.execute('create table test ( a int ) ENGINE=InnoDB') - c.begin() - cur.execute('insert into test values ((1))') - raise ValueError('pseudo abort') - c = self.connect() - with pytest.warns(DeprecationWarning): - with c as cur: - cur.execute('select count(*) from test') - self.assertEqual(0, cur.fetchone()[0]) - cur.execute('insert into test values ((1))') - with pytest.warns(DeprecationWarning): - with c as cur: - cur.execute('select count(*) from test') - self.assertEqual(1,cur.fetchone()[0]) - cur.execute('drop table test') - def test_set_charset(self): c = self.connect() c.set_charset('utf8mb4')