Skip to content

Remove context manager #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 0 additions & 21 deletions pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down