Skip to content

Commit bcc2be3

Browse files
committed
Merge branch 'pyupgrade-37-plus' (#930)
2 parents 7ddfd3f + 98ad0fe commit bcc2be3

File tree

10 files changed

+33
-32
lines changed

10 files changed

+33
-32
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ next (unreleased)
1414

1515
* Fix debug log level with sha256_password authentication #863
1616

17+
* Modernized code with `pyupgrade <https://github.com/asottile/pyupgrade>`_ to Python 3.7+ syntax #930
18+
1719
0.1.1 (2022-05-08)
1820
^^^^^^^^^^^^^^^^^^
1921

aiomysql/connection.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ async def _connect(self):
542542
self.connected_time = self._loop.time()
543543

544544
if self.sql_mode is not None:
545-
await self.query("SET sql_mode=%s" % (self.sql_mode,))
545+
await self.query(f"SET sql_mode={self.sql_mode}")
546546

547547
if self.init_command is not None:
548548
await self.query(self.init_command)
@@ -659,8 +659,8 @@ async def _read_bytes(self, num_bytes):
659659
msg = "Lost connection to MySQL server during query"
660660
self.close()
661661
raise OperationalError(CR.CR_SERVER_LOST, msg) from e
662-
except (IOError, OSError) as e:
663-
msg = "Lost connection to MySQL server during query (%s)" % (e,)
662+
except OSError as e:
663+
msg = f"Lost connection to MySQL server during query ({e})"
664664
self.close()
665665
raise OperationalError(CR.CR_SERVER_LOST, msg) from e
666666
return data
@@ -899,7 +899,7 @@ async def _process_auth(self, plugin_name, auth_packet):
899899
data = self._password.encode('latin1') + b'\0'
900900
else:
901901
raise OperationalError(
902-
2059, "Authentication plugin '{0}'"
902+
2059, "Authentication plugin '{}'"
903903
" not configured".format(plugin_name)
904904
)
905905

@@ -936,7 +936,7 @@ async def caching_sha2_password_auth(self, pkt):
936936
if not pkt.is_extra_auth_data():
937937
raise OperationalError(
938938
"caching sha2: Unknown packet "
939-
"for fast auth: {0}".format(pkt._data[:1])
939+
"for fast auth: {}".format(pkt._data[:1])
940940
)
941941

942942
# magic numbers:
@@ -955,7 +955,7 @@ async def caching_sha2_password_auth(self, pkt):
955955

956956
if n != 4:
957957
raise OperationalError("caching sha2: Unknown "
958-
"result for fast auth: {0}".format(n))
958+
"result for fast auth: {}".format(n))
959959

960960
logger.debug("caching sha2: Trying full auth...")
961961

@@ -975,7 +975,7 @@ async def caching_sha2_password_auth(self, pkt):
975975
if not pkt.is_extra_auth_data():
976976
raise OperationalError(
977977
"caching sha2: Unknown packet "
978-
"for public key: {0}".format(pkt._data[:1])
978+
"for public key: {}".format(pkt._data[:1])
979979
)
980980

981981
self.server_public_key = pkt._data[1:]
@@ -1126,7 +1126,7 @@ def _ensure_alive(self):
11261126

11271127
def __del__(self):
11281128
if self._writer:
1129-
warnings.warn("Unclosed connection {!r}".format(self),
1129+
warnings.warn(f"Unclosed connection {self!r}",
11301130
ResourceWarning)
11311131
self.close()
11321132

@@ -1351,7 +1351,7 @@ async def _get_descriptions(self):
13511351
self.description = tuple(description)
13521352

13531353

1354-
class LoadLocalFile(object):
1354+
class LoadLocalFile:
13551355
def __init__(self, filename, connection):
13561356
self.filename = filename
13571357
self.connection = connection
@@ -1364,8 +1364,8 @@ def _open_file(self):
13641364
def opener(filename):
13651365
try:
13661366
self._file_object = open(filename, 'rb')
1367-
except IOError as e:
1368-
msg = "Can't find file '{0}'".format(filename)
1367+
except OSError as e:
1368+
msg = f"Can't find file '{filename}'"
13691369
raise OperationalError(1017, msg) from e
13701370

13711371
fut = self._loop.run_in_executor(self._executor, opener, self.filename)
@@ -1384,7 +1384,7 @@ def freader(chunk_size):
13841384
except Exception as e:
13851385
self._file_object.close()
13861386
self._file_object = None
1387-
msg = "Error reading file {}".format(self.filename)
1387+
msg = f"Error reading file {self.filename}"
13881388
raise OperationalError(1024, msg) from e
13891389
return chunk
13901390

aiomysql/cursors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _escape_args(self, args, conn):
196196
if isinstance(args, (tuple, list)):
197197
return tuple(conn.escape(arg) for arg in args)
198198
elif isinstance(args, dict):
199-
return dict((key, conn.escape(val)) for (key, val) in args.items())
199+
return {key: conn.escape(val) for (key, val) in args.items()}
200200
else:
201201
# If it's not a dictionary let's try escaping it anyways.
202202
# Worst case it will throw a Value error
@@ -357,7 +357,7 @@ async def callproc(self, procname, args=()):
357357
await self.nextset()
358358

359359
_args = ','.join('@_%s_%d' % (procname, i) for i in range(len(args)))
360-
q = "CALL %s(%s)" % (procname, _args)
360+
q = f"CALL {procname}({_args})"
361361
await self._query(q)
362362
self._executed = q
363363
return args

aiomysql/sa/transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from . import exc
44

55

6-
class Transaction(object):
6+
class Transaction:
77
"""Represent a database transaction in progress.
88
99
The Transaction object is procured by
@@ -114,7 +114,7 @@ class NestedTransaction(Transaction):
114114
_savepoint = None
115115

116116
def __init__(self, connection, parent):
117-
super(NestedTransaction, self).__init__(connection, parent)
117+
super().__init__(connection, parent)
118118

119119
async def _do_rollback(self):
120120
assert self._savepoint is not None, "Broken transaction logic"

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# aiomysql documentation build configuration file, created by
54
# sphinx-quickstart on Sun Jan 18 22:02:31 2015.

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def pytest_generate_tests(metafunc):
4040
ids.append(label)
4141
else:
4242
mysql_addresses.append(opt_mysql_unix_socket[i])
43-
ids.append("unix{}".format(i))
43+
ids.append(f"unix{i}")
4444

4545
opt_mysql_address = list(metafunc.config.getoption("mysql_address"))
4646
for i in range(len(opt_mysql_address)):
@@ -49,7 +49,7 @@ def pytest_generate_tests(metafunc):
4949
ids.append(label)
5050
else:
5151
addr = opt_mysql_address[i]
52-
ids.append("tcp{}".format(i))
52+
ids.append(f"tcp{i}")
5353

5454
if ":" in addr:
5555
addr = addr.split(":", 1)
@@ -232,7 +232,7 @@ def _register_table(table_name):
232232
yield _register_table
233233
for t in table_list:
234234
# TODO: probably this is not safe code
235-
sql = "DROP TABLE IF EXISTS {};".format(t)
235+
sql = f"DROP TABLE IF EXISTS {t};"
236236
loop.run_until_complete(cursor.execute(sql))
237237

238238

tests/test_basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def test_datatypes(connection, cursor, datatype_table):
2828
# insert values
2929
v = (
3030
True, -3, 123456789012, 5.7, "hello'\" world",
31-
u"Espa\xc3\xb1ol",
31+
"Espa\xc3\xb1ol",
3232
"binary\x00data".encode(encoding),
3333
datetime.date(1988, 2, 2),
3434
datetime.datetime.now().replace(microsecond=0),
@@ -148,10 +148,10 @@ async def test_binary_data(cursor, table_cleanup):
148148
async def test_untyped_convertion_to_null_and_empty_string(cursor):
149149
await cursor.execute("select null,''")
150150
r = await cursor.fetchone()
151-
assert (None, u'') == r
151+
assert (None, '') == r
152152
await cursor.execute("select '',null")
153153
r = await cursor.fetchone()
154-
assert (u'', None) == r
154+
assert ('', None) == r
155155

156156

157157
@pytest.mark.run_loop

tests/test_issues.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ async def test_issue_15(connection):
122122
await c.execute("create table issue15 (t varchar(32))")
123123
try:
124124
await c.execute("insert into issue15 (t) values (%s)",
125-
(u'\xe4\xf6\xfc',))
125+
('\xe4\xf6\xfc',))
126126
await c.execute("select t from issue15")
127127
r = await c.fetchone()
128-
assert u'\xe4\xf6\xfc' == r[0]
128+
assert '\xe4\xf6\xfc' == r[0]
129129
finally:
130130
await c.execute("drop table issue15")
131131

@@ -412,8 +412,8 @@ async def test_issue_175(connection):
412412
conn = connection
413413
cur = await conn.cursor()
414414
for length in (200, 300):
415-
cols = ', '.join('c{0} integer'.format(i) for i in range(length))
416-
sql = 'create table test_field_count ({0})'.format(cols)
415+
cols = ', '.join(f'c{i} integer' for i in range(length))
416+
sql = f'create table test_field_count ({cols})'
417417
try:
418418
await cur.execute(sql)
419419
await cur.execute('select * from test_field_count')

tests/test_sha_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
def ensure_mysql_version(mysql_server):
2525
if mysql_server["db_type"] != "mysql" \
2626
or mysql_server["server_version_tuple_short"] != (8, 0):
27-
pytest.skip("Not applicable for {0} version: {1}"
27+
pytest.skip("Not applicable for {} version: {}"
2828
.format(mysql_server["db_type"],
2929
mysql_server["server_version_tuple_short"]))
3030

tests/test_sscursor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ async def test_ssursor(connection):
4242
cursor = await conn.cursor(SSCursor)
4343
# Create table
4444
await cursor.execute('DROP TABLE IF EXISTS tz_data;')
45-
await cursor.execute(('CREATE TABLE tz_data ('
46-
'region VARCHAR(64),'
47-
'zone VARCHAR(64),'
48-
'name VARCHAR(64))'))
45+
await cursor.execute('CREATE TABLE tz_data ('
46+
'region VARCHAR(64),'
47+
'zone VARCHAR(64),'
48+
'name VARCHAR(64))')
4949

5050
# Test INSERT
5151
for i in DATA:

0 commit comments

Comments
 (0)