8000 Run pyupgrade (#1118) · PyMySQL/PyMySQL@103004d · GitHub
[go: up one dir, main page]

Skip to content

Commit 103004d

Browse files
authored
Run pyupgrade (#1118)
1 parent 9a694a1 commit 103004d

10 files changed

+26
-24
lines changed

pymysql/charset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def __init__(self, id, name, collation, is_default):
77
self.is_default = is_default == "Yes"
88

99
def __repr__(self):
10-
return "Charset(id=%s, name=%r, collation=%r)" % (
10+
return "Charset(id={}, name={!r}, collation={!r})".format(
1111
self.id,
1212
self.name,
1313
self.collation,

pymysql/connections.py

+11-9
< 67E6 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,9 @@ def escape_string(self, s):
528528

529529
def _quote_bytes(self, s):
530530
if self.server_status & SERVER_STATUS.SERVER_STATUS_NO_BACKSLASH_ESCAPES:
531-
return "'%s'" % (s.replace(b"'", b"''").decode("ascii", "surrogateescape"),)
531+
return "'{}'".format(
532+
s.replace(b"'", b"''").decode("ascii", "surrogateescape")
533+
)
532534
return converters.escape_bytes(s)
533535

534536
def cursor(self, cursor=None):
@@ -621,7 +623,7 @@ def connect(self, sock=None):
621623
(self.host, self.port), self.connect_timeout, **kwargs
622624
)
623625
break
624-
except (OSError, IOError) as e:
626+
except OSError as e:
625627
if e.errno == errno.EINTR:
626628
continue
627629
raise
@@ -662,7 +664,7 @@ def connect(self, sock=None):
662664
if isinstance(e, (OSError, IOError)):
663665
exc = err.OperationalError(
664666
CR.CR_CONN_HOST_ERROR,
665-
"Can't connect to MySQL server on %r (%s)" % (self.host, e),
667+
f"Can't connect to MySQL server on {self.host!r} ({e})",
666668
)
667669
# Keep original exception and traceback to investigate error.
668670
exc.original_exception = e
@@ -739,13 +741,13 @@ def _read_bytes(self, num_bytes):
739741
try:
740742
data = self._rfile.read(num_bytes)
741743
break
742-
except (IOError, OSError) as e:
744+
except OSError as e:
743745
if e.errno == errno.EINTR:
744746
continue
745747
self._force_close()
746748
raise err.OperationalError(
747749
CR.CR_SERVER_LOST,
748-
"Lost connection to MySQL server during query (%s)" % (e,),
750+
f"Lost connection to MySQL server during query ({e})",
749751
)
750752
except BaseException:
751753
# Don't convert unknown exception to MySQLError.
@@ -762,10 +764,10 @@ def _write_bytes(self, data):
762764
self._sock.settimeout(self._write_timeout)
763765
try:
764766
self._sock.sendall(data)
765-
except IOError as e:
767+
except OSError as e:
766768
self._force_close()
767769
raise err.OperationalError(
768-
CR.CR_SERVER_GONE_ERROR, "MySQL server has gone away (%r)" % (e,)
770+
CR.CR_SERVER_GONE_ERROR, f"MySQL server has gone away ({e!r})"
769771
)
770772

771773
def _read_query_result(self, unbuffered=False):
@@ -1006,7 +1008,7 @@ def _process_auth(self, plugin_name, auth_packet):
10061008
else:
10071009
raise err.OperationalError(
10081010
CR.CR_AUTH_PLUGIN_CANNOT_LOAD,
1009-
"Authentication plugin '%s' not configured" % (plugin_name,),
1011+
f"Authentication plugin '{plugin_name}' not configured",
10101012
)
10111013
pkt = self._read_packet()
10121014
pkt.check_error()
@@ -1382,7 +1384,7 @@ def send_data(self):
13821384
if not chunk:
13831385
break
13841386
conn.write_packet(chunk)
1385-
except IOError:
1387+
except OSError:
13861388
raise err.OperationalError(
13871389
ER.FILE_NOT_FOUND,
13881390
f"Can't find file '{self.filename}'",

pymysql/cursors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def callproc(self, procname, args=()):
262262
)
263263
self.nextset()
264264

265-
q = "CALL %s(%s)" % (
265+
q = "CALL {}({})".format(
266266
procname,
267267
",".join(["@_%s_%d" % (procname, i) for i in range(len(args))]),
268268
)
@@ -383,7 +383,7 @@ class DictCursorMixin:
383383
dict_type = dict
384384

385385
def _do_get_result(self):
386-
super(DictCursorMixin, self)._do_get_result()
386+
super()._do_get_result()
387387
fields = []
388388
if self.description:
389389
for f in self._result.fields:

pymysql/protocol.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def printable(data):
3535
dump_data = [data[i : i + 16] for i in range(0, min(len(data), 256), 16)]
3636
for d in dump_data:
3737
print(
38-
" ".join("{:02X}".format(x) for x in d)
38+
" ".join(f"{x:02X}" for x in d)
3939
+ " " * (16 - len(d))
4040
+ " " * 2
4141
+ "".join(printable(x) for x in d)
@@ -275,7 +275,7 @@ def get_column_length(self):
275275
return self.length
276276

277277
def __str__(self):
278-
return "%s %r.%r.%r, type=%s, flags=%x" % (
278+
return "{} {!r}.{!r}.{!r}, type={}, flags={:x}".format(
279279
self.__class__,
280280
self.db,
281281
self.table_name,

pymysql/tests/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def safe_create_table(self, connection, tablename, ddl, cleanup=True):
9898

9999
with warnings.catch_warnings():
100100
warnings.simplefilter("ignore")
101-
cursor.execute("drop table if exists `%s`" % (tablename,))
101+
cursor.execute(f"drop table if exists `{tablename}`")
102102
cursor.execute(ddl)
103103
cursor.close()
104104
if cleanup:
@@ -108,5 +108,5 @@ def drop_table(self, connection, tablename):
108108
cursor = connection.cursor()
109109
with warnings.catch_warnings():
110110
warnings.simplefilter("ignore")
111-
cursor.execute("drop table if exists `%s`" % (tablename,))
111+
cursor.execute(f"drop table if exists `{tablename}`")
112112
cursor.close()

pymysql/tests/test_DictCursor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestDictCursor(base.PyMySQLTestCase):
1313
cursor_type = pymysql.cursors.DictCursor
1414

1515
def setUp(self):
16-
super(TestDictCursor, self).setUp()
16+
super().setUp()
1717
self.conn = conn = self.connect()
1818
c = conn.cursor(self.cursor_type)
1919

@@ -36,7 +36,7 @@ def setUp(self):
3636
def tearDown(self):
3737
c = self.conn.cursor()
3838
c.execute("drop table dictcursor")
39-
super(TestDictCursor, self).tearDown()
39+
super().tearDown()
4040

4141
def _ensure_cursor_expired(self, cursor):
4242
pass

pymysql/tests/test_basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class TestBulkInserts(base.PyMySQLTestCase):
332332
cursor_type = pymysql.cursors.DictCursor
333333

334334
def setUp(self):
335-
super(TestBulkInserts, self).setUp()
335+
super().setUp()
336336
self.conn = conn = self.connect()
337337

338338
# create a table and some data to query

pymysql/tests/test_connection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, c, user, db, auth=None, authdata=None, password=None):
2828
# already exists - TODO need to check the same plugin applies
2929
self._created = False
3030
try:
31-
c.execute("GRANT SELECT ON %s.* TO %s" % (db, user))
31+
c.execute(f"GRANT SELECT ON {db}.* TO {user}")
3232
self._grant = True
3333
except pymysql.err.InternalError:
3434
self._grant = False
@@ -38,7 +38,7 @@ def __enter__(self):
3838

3939
def __exit__(self, exc_type, exc_value, traceback):
4040
if self._grant:
41-
self._c.execute("REVOKE SELECT ON %s.* FROM %s" % (self._db, self._user))
41+
self._c.execute(f"REVOKE SELECT ON {self._db}.* FROM {self._user}")
4242
if self._created:
4343
self._c.execute("DROP USER %s" % self._user)
4444

pymysql/tests/test_cursor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class CursorTest(base.PyMySQLTestCase):
99
def setUp(self):
10-
super(CursorTest, self).setUp()
10+
super().setUp()
1111

1212
conn = self.connect()
1313
self.safe_create_table(

pymysql/tests/test_issues.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ def test_issue_175(self):
379379
conn = self.connect()
380380
cur = conn.cursor()
381381
for length in (200, 300):
382-
columns = ", ".join("c{0} integer".format(i) for i in range(length))
383-
sql = "create table test_field_count ({0})".format(columns)
382+
columns = ", ".join(f"c{i} integer" for i in range(length))
383+
sql = f"create table test_field_count ({columns})"
384384
try:
385385
cur.execute(sql)
386386
cur.execute("select * from test_field_count")

0 commit comments

Comments
 (0)
0