Skip to content

Commit

Permalink
remove deprecated Pool.get and deprecated with await pool syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You committed Jan 29, 2022
1 parent 1558b4a commit ab47f38
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions aiomysql/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/example_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand Down
19 changes: 2 additions & 17 deletions tests/test_async_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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;')
8 changes: 4 additions & 4 deletions tests/test_sha_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
4 changes: 2 additions & 2 deletions tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
Expand Down Expand Up @@ -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;")
Expand Down

0 comments on commit ab47f38

Please sign in to comment.