Skip to content

Commit 3818ad0

Browse files
authored
Use f-string (PyMySQL#928)
1 parent d9b67a3 commit 3818ad0

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

pymysql/connections.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ def _get_descriptions(self):
13311331
if converter is converters.through:
13321332
converter = None
13331333
if DEBUG:
1334-
print("DEBUG: field={}, converter={}".format(field, converter))
1334+
print(f"DEBUG: field={field}, converter={converter}")
13351335
self.converters.append((encoding, converter))
13361336

13371337
eof_packet = self.connection._read_packet()
@@ -1361,9 +1361,7 @@ def send_data(self):
13611361
break
13621362
conn.write_packet(chunk)
13631363
except IOError:
1364-
raise err.OperationalError(
1365-
1017, "Can't find file '{0}'".format(self.filename)
1366-
)
1364+
raise err.OperationalError(1017, f"Can't find file '{self.filename}'")
13671365
finally:
13681366
# send the empty packet to signify we are done sending data
13691367
conn.write_packet(b"")

pymysql/cursors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def callproc(self, procname, args=()):
242242
"""
243243
conn = self._get_db()
244244
if args:
245-
fmt = "@_{0}_%d=%s".format(procname)
245+
fmt = f"@_{procname}_%d=%s"
246246
self._query(
247247
"SET %s"
248248
% ",".join(

pymysql/protocol.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ class EOFPacketWrapper:
323323
def __init__(self, from_packet):
324324
if not from_packet.is_eof_packet():
325325
raise ValueError(
326-
"Cannot create '{0}' object from invalid packet type".format(
327-
self.__class__
328-
)
326+
f"Cannot create '{self.__class__}' object from invalid packet type"
329327
)
330328

331329
self.packet = from_packet
@@ -348,9 +346,7 @@ class LoadLocalPacketWrapper:
348346
def __init__(self, from_packet):
349347
if not from_packet.is_load_local_packet():
350348
raise ValueError(
351-
"Cannot create '{0}' object from invalid packet type".format(
352-
self.__class__
353-
)
349+
f"Cannot create '{self.__class__}' object from invalid packet type"
354350
)
355351

356352
self.packet = from_packet

pymysql/tests/test_load_local.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ def test_load_file(self):
3535
)
3636
try:
3737
c.execute(
38-
(
39-
"LOAD DATA LOCAL INFILE '{0}' INTO TABLE "
40-
+ "test_load_local FIELDS TERMINATED BY ','"
41-
).format(filename)
38+
f"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE test_load_local FIELDS TERMINATED BY ','"
4239
)
4340
c.execute("SELECT COUNT(*) FROM test_load_local")
4441
self.assertEqual(22749, c.fetchone()[0])
@@ -55,10 +52,7 @@ def test_unbuffered_load_file(self):
5552
)
5653
try:
5754
c.execute(
58-
(
59-
"LOAD DATA LOCAL INFILE '{0}' INTO TABLE "
60-
+ "test_load_local FIELDS TERMINATED BY ','"
61-
).format(filename)
55+
f"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE test_load_local FIELDS TERMINATED BY ','"
6256
)
6357
c.execute("SELECT COUNT(*) FROM test_load_local")
6458
self.assertEqual(22749, c.fetchone()[0])

0 commit comments

Comments
 (0)