From ab47f38554d17ebe61a5a83755aa6b8243b5e8e1 Mon Sep 17 00:00:00 2001 From: Richard Schwab Date: Sat, 29 Jan 2022 03:38:37 +0100 Subject: [PATCH] remove deprecated Pool.get and deprecated `with await pool` syntax --- CHANGES.txt | 2 ++ aiomysql/pool.py | 14 +++----------- examples/example_ssl.py | 2 +- tests/test_async_with.py | 19 ++----------------- tests/test_issues.py | 2 +- tests/test_pool.py | 22 +++++++++++----------- tests/test_sha_connection.py | 8 ++++---- tests/test_ssl.py | 4 ++-- 8 files changed, 26 insertions(+), 47 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8f63c7e8..4f2bed3f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,8 @@ To be included in 1.0.0 (unreleased) * Test suite now also tests unix socket connections #696 * Fix SSCursor raising InternalError when last result was not fully retrieved #635 * Remove deprecated no_delay argument #702 +* Remove deprecated Pool.get #703 +* Remove deprecated with await pool syntax #703 0.0.22 (2021-11-14) diff --git a/aiomysql/pool.py b/aiomysql/pool.py index 3eacb47d..7859e2c4 100644 --- a/aiomysql/pool.py +++ b/aiomysql/pool.py @@ -223,12 +223,6 @@ def release(self, conn): fut = self._loop.create_task(self._wakeup()) return fut - def get(self): - warnings.warn("pool.get deprecated use pool.acquire instead", - DeprecationWarning, - stacklevel=2) - return _PoolConnectionContextManager(self, None) - def __enter__(self): raise RuntimeError( '"yield from" should be used as context manager expression') @@ -255,11 +249,9 @@ def __iter__(self): return _PoolConnectionContextManager(self, conn) def __await__(self): - msg = "with await pool as conn deprecated, use" \ - "async with pool.acquire() as conn instead" - warnings.warn(msg, DeprecationWarning, stacklevel=2) - conn = yield from self.acquire() - return _PoolConnectionContextManager(self, conn) + msg = "\"with await pool\" is no longer supported, use " \ + "\"async with pool.acquire() as conn\" instead" + raise RuntimeError(msg) async def __aenter__(self): return self diff --git a/examples/example_ssl.py b/examples/example_ssl.py index e66c267d..bc1d1665 100644 --- a/examples/example_ssl.py +++ b/examples/example_ssl.py @@ -13,7 +13,7 @@ async def main(): password='rootpw', ssl=ctx, auth_plugin='mysql_clear_password') as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: async with conn.cursor() as cur: # Run simple command await cur.execute("SHOW DATABASES;") diff --git a/tests/test_async_with.py b/tests/test_async_with.py index 2143167d..a043950c 100644 --- a/tests/test_async_with.py +++ b/tests/test_async_with.py @@ -127,24 +127,9 @@ async def test_pool(table, pool_creator, loop): @pytest.mark.run_loop async def test_create_pool_deprecations(mysql_params, loop): async with create_pool(loop=loop, **mysql_params) as pool: - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - async with pool.get() as conn: + with pytest.raises(RuntimeError): + with await pool: pass - # The first warning emitted is expected to be DeprecationWarning: - # in the past, we used to check for the last one but this assumption - # breaks under Python 3.7 that also emits a `ResourceWarning` when - # executed with `PYTHONASYNCIODEBUG=1`. - assert issubclass(w[0].category, DeprecationWarning) - assert conn.closed - - async with create_pool(loop=loop, **mysql_params) as pool: - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - with await pool as conn: - pass - assert issubclass(w[-1].category, DeprecationWarning) - assert conn.closed @pytest.mark.run_loop diff --git a/tests/test_issues.py b/tests/test_issues.py index c25e292f..51dcaf0f 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -423,7 +423,7 @@ async def test_issue_175(connection): async def test_issue_323(mysql_server, loop, recwarn): async with aiomysql.create_pool(**mysql_server['conn_params'], loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: async with conn.cursor() as cur: drop_db = "DROP DATABASE IF EXISTS bugtest;" await cur.execute(drop_db) diff --git a/tests/test_pool.py b/tests/test_pool.py index fac5c2d2..39d03c9c 100644 --- a/tests/test_pool.py +++ b/tests/test_pool.py @@ -79,7 +79,7 @@ async def test_bad_context_manager_usage(pool_creator): @pytest.mark.run_loop async def test_context_manager(pool_creator): pool = await pool_creator(minsize=10, maxsize=10) - async with pool.get() as conn: + async with pool.acquire() as conn: assert isinstance(conn, Connection) assert 9 == pool.freesize assert {conn} == pool._used @@ -101,7 +101,7 @@ async def test_initial_empty(pool_creator): assert 0 == pool.size assert 0 == pool.freesize - async with pool.get(): + async with pool.acquire(): assert 1 == pool.size assert 0 == pool.freesize assert 1 == pool.size @@ -236,7 +236,7 @@ async def test_release_with_invalid_status_wait_release(pool_creator): @pytest.mark.run_loop async def test__fill_free(pool_creator, loop): pool = await pool_creator(minsize=1) - async with pool.get(): + async with pool.acquire(): assert 0 == pool.freesize assert 1 == pool.size @@ -256,7 +256,7 @@ async def test_connect_from_acquire(pool_creator): pool = await pool_creator(minsize=0) assert 0 == pool.freesize assert 0 == pool.size - async with pool.get(): + async with pool.acquire(): assert 1 == pool.size assert 0 == pool.freesize assert 1 == pool.size @@ -352,7 +352,7 @@ async def test_echo(pool_creator): pool = await pool_creator(echo=True) assert pool.echo - async with pool.get() as conn: + async with pool.acquire() as conn: assert conn.echo @@ -481,7 +481,7 @@ async def test_cancelled_connection(pool_creator, loop): pool = await pool_creator(minsize=0, maxsize=1) try: - async with pool.get() as conn: + async with pool.acquire() as conn: curs = await conn.cursor() # Cancel a cursor in the middle of execution, before it # could read even the first packet (SLEEP assures the @@ -494,7 +494,7 @@ async def test_cancelled_connection(pool_creator, loop): except asyncio.CancelledError: pass - async with pool.get() as conn: + async with pool.acquire() as conn: cur2 = await conn.cursor() res = await cur2.execute("SELECT 2 as value, 0 as xxx") names = [x[0] for x in cur2.description] @@ -508,7 +508,7 @@ async def test_cancelled_connection(pool_creator, loop): @pytest.mark.run_loop async def test_pool_with_connection_recycling(pool_creator, loop): pool = await pool_creator(minsize=1, maxsize=1, pool_recycle=3) - async with pool.get() as conn: + async with pool.acquire() as conn: cur = await conn.cursor() await cur.execute('SELECT 1;') val = await cur.fetchone() @@ -517,7 +517,7 @@ async def test_pool_with_connection_recycling(pool_creator, loop): await asyncio.sleep(5) assert 1 == pool.freesize - async with pool.get() as conn: + async with pool.acquire() as conn: cur = await conn.cursor() await cur.execute('SELECT 1;') val = await cur.fetchone() @@ -528,13 +528,13 @@ async def test_pool_with_connection_recycling(pool_creator, loop): async def test_pool_drops_connection_with_exception(pool_creator, loop): pool = await pool_creator(minsize=1, maxsize=1) - async with pool.get() as conn: + async with pool.acquire() as conn: cur = await conn.cursor() await cur.execute('SELECT 1;') connection, = pool._free connection._writer._protocol.connection_lost(IOError()) - async with pool.get() as conn: + async with pool.acquire() as conn: cur = await conn.cursor() await cur.execute('SELECT 1;') diff --git a/tests/test_sha_connection.py b/tests/test_sha_connection.py index 0789d162..6f233df3 100644 --- a/tests/test_sha_connection.py +++ b/tests/test_sha_connection.py @@ -30,7 +30,7 @@ async def test_sha256_nopw(mysql_server, loop): async with create_pool(**connection_data, loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: # User doesnt have any permissions to look at DBs # But as 8.0 will default to caching_sha2_password assert conn._auth_plugin_used == 'sha256_password' @@ -52,7 +52,7 @@ async def test_sha256_pw(mysql_server, loop): async with create_pool(**connection_data, loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: # User doesnt have any permissions to look at DBs # But as 8.0 will default to caching_sha2_password assert conn._auth_plugin_used == 'sha256_password' @@ -67,7 +67,7 @@ async def test_cached_sha256_nopw(mysql_server, loop): async with create_pool(**connection_data, loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: # User doesnt have any permissions to look at DBs # But as 8.0 will default to caching_sha2_password assert conn._auth_plugin_used == 'caching_sha2_password' @@ -82,7 +82,7 @@ async def test_cached_sha256_pw(mysql_server, loop): async with create_pool(**connection_data, loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: # User doesnt have any permissions to look at DBs # But as 8.0 will default to caching_sha2_password assert conn._auth_plugin_used == 'caching_sha2_password' diff --git a/tests/test_ssl.py b/tests/test_ssl.py index 140c164f..9cc45fce 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -10,7 +10,7 @@ async def test_tls_connect(mysql_server, loop, mysql_params): async with create_pool(**mysql_server['conn_params'], loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: async with conn.cursor() as cur: # Run simple command await cur.execute("SHOW DATABASES;") @@ -42,7 +42,7 @@ async def test_auth_plugin_renegotiation(mysql_server, loop, mysql_params): async with create_pool(**mysql_server['conn_params'], auth_plugin='mysql_clear_password', loop=loop) as pool: - async with pool.get() as conn: + async with pool.acquire() as conn: async with conn.cursor() as cur: # Run simple command await cur.execute("SHOW DATABASES;")