Skip to content

Commit

Permalink
remove deprecated Pool.get
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You committed Apr 15, 2022
1 parent 5a42bc1 commit 2239d89
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changes
-------

next (unreleased)
^^^^^^^^^^^^^^^^^

* Remove deprecated Pool.get #706


0.1.0 (2022-04-11)
^^^^^^^^^^^^^^^^^^

Expand Down
6 changes: 0 additions & 6 deletions aiomysql/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,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 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
12 changes: 0 additions & 12 deletions tests/test_async_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,6 @@ 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:
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")
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 @@ -353,7 +353,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 @@ -482,7 +482,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 @@ -495,7 +495,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 @@ -509,7 +509,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 @@ -518,7 +518,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 @@ -529,14 +529,14 @@ 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;')

Expand Down
8 changes: 4 additions & 4 deletions tests/test_sha_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 @@ -62,7 +62,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 @@ -78,7 +78,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 @@ -94,7 +94,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 2239d89

Please sign in to comment.