Skip to content

Commit 4c555f3

Browse files
committed
remove deprecated Pool.get and deprecated with await pool syntax
1 parent 1558b4a commit 4c555f3

File tree

8 files changed

+26
-50
lines changed

8 files changed

+26
-50
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ To be included in 1.0.0 (unreleased)
1414
* Test suite now also tests unix socket connections #696
1515
* Fix SSCursor raising InternalError when last result was not fully retrieved #635
1616
* Remove deprecated no_delay argument #702
17+
* Remove deprecated Pool.get #703
18+
* Remove deprecated with await pool syntax #703
1719

1820

1921
0.0.22 (2021-11-14)

aiomysql/pool.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import asyncio
55
import collections
6-
import warnings
76

87
from .connection import connect
98
from .utils import (_PoolContextManager, _PoolConnectionContextManager,
@@ -223,12 +222,6 @@ def release(self, conn):
223222
fut = self._loop.create_task(self._wakeup())
224223
return fut
225224

226-
def get(self):
227-
warnings.warn("pool.get deprecated use pool.acquire instead",
228-
DeprecationWarning,
229-
stacklevel=2)
230-
return _PoolConnectionContextManager(self, None)
231-
232225
def __enter__(self):
233226
raise RuntimeError(
234227
'"yield from" should be used as context manager expression')
@@ -255,11 +248,9 @@ def __iter__(self):
255248
return _PoolConnectionContextManager(self, conn)
256249

257250
def __await__(self):
258-
msg = "with await pool as conn deprecated, use" \
259-
"async with pool.acquire() as conn instead"
260-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
261-
conn = yield from self.acquire()
262-
return _PoolConnectionContextManager(self, conn)
251+
msg = "\"with await pool\" is no longer supported, use " \
252+
"\"async with pool.acquire() as conn\" instead"
253+
raise RuntimeError(msg)
263254

264255
async def __aenter__(self):
265256
return self

examples/example_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def main():
1313
password='rootpw', ssl=ctx,
1414
auth_plugin='mysql_clear_password') as pool:
1515

16-
async with pool.get() as conn:
16+
async with pool.acquire() as conn:
1717
async with conn.cursor() as cur:
1818
# Run simple command
1919
await cur.execute("SHOW DATABASES;")

tests/test_async_with.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import warnings
2-
31
import aiomysql
42
import pytest
53

@@ -127,24 +125,9 @@ async def test_pool(table, pool_creator, loop):
127125
@pytest.mark.run_loop
128126
async def test_create_pool_deprecations(mysql_params, loop):
129127
async with create_pool(loop=loop, **mysql_params) as pool:
130-
with warnings.catch_warnings(record=True) as w:
131-
warnings.simplefilter("always")
132-
async with pool.get() as conn:
133-
pass
134-
# The first warning emitted is expected to be DeprecationWarning:
135-
# in the past, we used to check for the last one but this assumption
136-
# breaks under Python 3.7 that also emits a `ResourceWarning` when
137-
# executed with `PYTHONASYNCIODEBUG=1`.
138-
assert issubclass(w[0].category, DeprecationWarning)
139-
assert conn.closed
140-
141-
async with create_pool(loop=loop, **mysql_params) as pool:
142-
with warnings.catch_warnings(record=True) as w:
143-
warnings.simplefilter("always")
144-
with await pool as conn:
128+
with pytest.raises(RuntimeError):
129+
with await pool:
145130
pass
146-
assert issubclass(w[-1].category, DeprecationWarning)
147-
assert conn.closed
148131

149132

150133
@pytest.mark.run_loop

tests/test_issues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ async def test_issue_175(connection):
423423
async def test_issue_323(mysql_server, loop, recwarn):
424424
async with aiomysql.create_pool(**mysql_server['conn_params'],
425425
loop=loop) as pool:
426-
async with pool.get() as conn:
426+
async with pool.acquire() as conn:
427427
async with conn.cursor() as cur:
428428
drop_db = "DROP DATABASE IF EXISTS bugtest;"
429429
await cur.execute(drop_db)

tests/test_pool.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def test_bad_context_manager_usage(pool_creator):
7979
@pytest.mark.run_loop
8080
async def test_context_manager(pool_creator):
8181
pool = await pool_creator(minsize=10, maxsize=10)
82-
async with pool.get() as conn:
82+
async with pool.acquire() as conn:
8383
assert isinstance(conn, Connection)
8484
assert 9 == pool.freesize
8585
assert {conn} == pool._used
@@ -101,7 +101,7 @@ async def test_initial_empty(pool_creator):
101101
assert 0 == pool.size
102102
assert 0 == pool.freesize
103103

104-
async with pool.get():
104+
async with pool.acquire():
105105
assert 1 == pool.size
106106
assert 0 == pool.freesize
107107
assert 1 == pool.size
@@ -236,7 +236,7 @@ async def test_release_with_invalid_status_wait_release(pool_creator):
236236
@pytest.mark.run_loop
237237
async def test__fill_free(pool_creator, loop):
238238
pool = await pool_creator(minsize=1)
239-
async with pool.get():
239+
async with pool.acquire():
240240
assert 0 == pool.freesize
241241
assert 1 == pool.size
242242

@@ -256,7 +256,7 @@ async def test_connect_from_acquire(pool_creator):
256256
pool = await pool_creator(minsize=0)
257257
assert 0 == pool.freesize
258258
assert 0 == pool.size
259-
async with pool.get():
259+
async with pool.acquire():
260260
assert 1 == pool.size
261261
assert 0 == pool.freesize
262262
assert 1 == pool.size
@@ -352,7 +352,7 @@ async def test_echo(pool_creator):
352352
pool = await pool_creator(echo=True)
353353
assert pool.echo
354354

355-
async with pool.get() as conn:
355+
async with pool.acquire() as conn:
356356
assert conn.echo
357357

358358

@@ -481,7 +481,7 @@ async def test_cancelled_connection(pool_creator, loop):
481481
pool = await pool_creator(minsize=0, maxsize=1)
482482

483483
try:
484-
async with pool.get() as conn:
484+
async with pool.acquire() as conn:
485485
curs = await conn.cursor()
486486
# Cancel a cursor in the middle of execution, before it
487487
# could read even the first packet (SLEEP assures the
@@ -494,7 +494,7 @@ async def test_cancelled_connection(pool_creator, loop):
494494
except asyncio.CancelledError:
495495
pass
496496

497-
async with pool.get() as conn:
497+
async with pool.acquire() as conn:
498498
cur2 = await conn.cursor()
499499
res = await cur2.execute("SELECT 2 as value, 0 as xxx")
500500
names = [x[0] for x in cur2.description]
@@ -508,7 +508,7 @@ async def test_cancelled_connection(pool_creator, loop):
508508
@pytest.mark.run_loop
509509
async def test_pool_with_connection_recycling(pool_creator, loop):
510510
pool = await pool_creator(minsize=1, maxsize=1, pool_recycle=3)
511-
async with pool.get() as conn:
511+
async with pool.acquire() as conn:
512512
cur = await conn.cursor()
513513
await cur.execute('SELECT 1;')
514514
val = await cur.fetchone()
@@ -517,7 +517,7 @@ async def test_pool_with_connection_recycling(pool_creator, loop):
517517
await asyncio.sleep(5)
518518

519519
assert 1 == pool.freesize
520-
async with pool.get() as conn:
520+
async with pool.acquire() as conn:
521521
cur = await conn.cursor()
522522
await cur.execute('SELECT 1;')
523523
val = await cur.fetchone()
@@ -528,13 +528,13 @@ async def test_pool_with_connection_recycling(pool_creator, loop):
528528
async def test_pool_drops_connection_with_exception(pool_creator, loop):
529529
pool = await pool_creator(minsize=1, maxsize=1)
530530

531-
async with pool.get() as conn:
531+
async with pool.acquire() as conn:
532532
cur = await conn.cursor()
533533
await cur.execute('SELECT 1;')
534534

535535
connection, = pool._free
536536
connection._writer._protocol.connection_lost(IOError())
537537

538-
async with pool.get() as conn:
538+
async with pool.acquire() as conn:
539539
cur = await conn.cursor()
540540
await cur.execute('SELECT 1;')

tests/test_sha_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def test_sha256_nopw(mysql_server, loop):
3030

3131
async with create_pool(**connection_data,
3232
loop=loop) as pool:
33-
async with pool.get() as conn:
33+
async with pool.acquire() as conn:
3434
# User doesnt have any permissions to look at DBs
3535
# But as 8.0 will default to caching_sha2_password
3636
assert conn._auth_plugin_used == 'sha256_password'
@@ -52,7 +52,7 @@ async def test_sha256_pw(mysql_server, loop):
5252

5353
async with create_pool(**connection_data,
5454
loop=loop) as pool:
55-
async with pool.get() as conn:
55+
async with pool.acquire() as conn:
5656
# User doesnt have any permissions to look at DBs
5757
# But as 8.0 will default to caching_sha2_password
5858
assert conn._auth_plugin_used == 'sha256_password'
@@ -67,7 +67,7 @@ async def test_cached_sha256_nopw(mysql_server, loop):
6767

6868
async with create_pool(**connection_data,
6969
loop=loop) as pool:
70-
async with pool.get() as conn:
70+
async with pool.acquire() as conn:
7171
# User doesnt have any permissions to look at DBs
7272
# But as 8.0 will default to caching_sha2_password
7373
assert conn._auth_plugin_used == 'caching_sha2_password'
@@ -82,7 +82,7 @@ async def test_cached_sha256_pw(mysql_server, loop):
8282

8383
async with create_pool(**connection_data,
8484
loop=loop) as pool:
85-
async with pool.get() as conn:
85+
async with pool.acquire() as conn:
8686
# User doesnt have any permissions to look at DBs
8787
# But as 8.0 will default to caching_sha2_password
8888
assert conn._auth_plugin_used == 'caching_sha2_password'

tests/test_ssl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async def test_tls_connect(mysql_server, loop, mysql_params):
1010

1111
async with create_pool(**mysql_server['conn_params'],
1212
loop=loop) as pool:
13-
async with pool.get() as conn:
13+
async with pool.acquire() as conn:
1414
async with conn.cursor() as cur:
1515
# Run simple command
1616
await cur.execute("SHOW DATABASES;")
@@ -42,7 +42,7 @@ async def test_auth_plugin_renegotiation(mysql_server, loop, mysql_params):
4242
async with create_pool(**mysql_server['conn_params'],
4343
auth_plugin='mysql_clear_password',
4444
loop=loop) as pool:
45-
async with pool.get() as conn:
45+
async with pool.acquire() as conn:
4646
async with conn.cursor() as cur:
4747
# Run simple command
4848
await cur.execute("SHOW DATABASES;")

0 commit comments

Comments
 (0)