Skip to content

Commit

Permalink
Use f-string (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Jan 4, 2021
1 parent d9b67a3 commit 3818ad0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
6 changes: 2 additions & 4 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ def _get_descriptions(self):
if converter is converters.through:
converter = None
if DEBUG:
print("DEBUG: field={}, converter={}".format(field, converter))
print(f"DEBUG: field={field}, converter={converter}")
self.converters.append((encoding, converter))

eof_packet = self.connection._read_packet()
Expand Down Expand Up @@ -1361,9 +1361,7 @@ def send_data(self):
break
conn.write_packet(chunk)
except IOError:
raise err.OperationalError(
1017, "Can't find file '{0}'".format(self.filename)
)
raise err.OperationalError(1017, f"Can't find file '{self.filename}'")
finally:
# send the empty packet to signify we are done sending data
conn.write_packet(b"")
2 changes: 1 addition & 1 deletion pymysql/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def callproc(self, procname, args=()):
"""
conn = self._get_db()
if args:
fmt = "@_{0}_%d=%s".format(procname)
fmt = f"@_{procname}_%d=%s"
self._query(
"SET %s"
% ",".join(
Expand Down
8 changes: 2 additions & 6 deletions pymysql/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ class EOFPacketWrapper:
def __init__(self, from_packet):
if not from_packet.is_eof_packet():
raise ValueError(
"Cannot create '{0}' object from invalid packet type".format(
self.__class__
)
f"Cannot create '{self.__class__}' object from invalid packet type"
)

self.packet = from_packet
Expand All @@ -348,9 +346,7 @@ class LoadLocalPacketWrapper:
def __init__(self, from_packet):
if not from_packet.is_load_local_packet():
raise ValueError(
"Cannot create '{0}' object from invalid packet type".format(
self.__class__
)
f"Cannot create '{self.__class__}' object from invalid packet type"
)

self.packet = from_packet
Expand Down
10 changes: 2 additions & 8 deletions pymysql/tests/test_load_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ def test_load_file(self):
)
try:
c.execute(
(
"LOAD DATA LOCAL INFILE '{0}' INTO TABLE "
+ "test_load_local FIELDS TERMINATED BY ','"
).format(filename)
f"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE test_load_local FIELDS TERMINATED BY ','"
)
c.execute("SELECT COUNT(*) FROM test_load_local")
self.assertEqual(22749, c.fetchone()[0])
Expand All @@ -55,10 +52,7 @@ def test_unbuffered_load_file(self):
)
try:
c.execute(
(
"LOAD DATA LOCAL INFILE '{0}' INTO TABLE "
+ "test_load_local FIELDS TERMINATED BY ','"
).format(filename)
f"LOAD DATA LOCAL INFILE '{filename}' INTO TABLE test_load_local FIELDS TERMINATED BY ','"
)
c.execute("SELECT COUNT(*) FROM test_load_local")
self.assertEqual(22749, c.fetchone()[0])
Expand Down

0 comments on commit 3818ad0

Please sign in to comment.