Skip to content

Commit

Permalink
Run pyupgrade --py38-plus (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane authored May 9, 2023
1 parent 418b68d commit 1f906e6
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion MySQLdb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def set_character_set(self, charset, collation=None):
super().set_character_set(charset)
self.encoding = _charset_to_encoding.get(charset, charset)
if collation:
self.query("SET NAMES %s COLLATE %s" % (charset, collation))
self.query(f"SET NAMES {charset} COLLATE {collation}")
self.store_result()

def set_sql_mode(self, sql_mode):
Expand Down
2 changes: 1 addition & 1 deletion MySQLdb/constants/CR.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
data[value].add(name)
for value, names in sorted(data.items()):
for name in sorted(names):
print("{} = {}".format(name, value))
print(f"{name} = {value}")
if error_last is not None:
print("ERROR_LAST = %s" % error_last)

Expand Down
2 changes: 1 addition & 1 deletion MySQLdb/constants/ER.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
data[value].add(name)
for value, names in sorted(data.items()):
for name in sorted(names):
print("{} = {}".format(name, value))
print(f"{name} = {value}")
if error_last is not None:
print("ERROR_LAST = %s" % error_last)

Expand Down
2 changes: 1 addition & 1 deletion setup_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def enabled(options, option):
elif s in ("no", "false", "0", "n"):
return False
else:
raise ValueError("Unknown value {} for option {}".format(value, option))
raise ValueError(f"Unknown value {value} for option {option}")


def create_release_file(metadata):
Expand Down
14 changes: 7 additions & 7 deletions tests/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def tearDown(self):

del self.cursor
orphans = gc.collect()
self.failIf(
self.assertFalse(
orphans, "%d orphaned objects found after deleting cursor" % orphans
)

del self.connection
orphans = gc.collect()
self.failIf(
self.assertFalse(
orphans, "%d orphaned objects found after deleting connection" % orphans
)

Expand Down Expand Up @@ -82,7 +82,7 @@ def create_table(self, columndefs):
def check_data_integrity(self, columndefs, generator):
# insert
self.create_table(columndefs)
insert_statement = "INSERT INTO %s VALUES (%s)" % (
insert_statement = "INSERT INTO {} VALUES ({})".format(
self.table,
",".join(["%s"] * len(columndefs)),
)
Expand Down Expand Up @@ -113,7 +113,7 @@ def generator(row, col):
return ("%i" % (row % 10)) * 255

self.create_table(columndefs)
insert_statement = "INSERT INTO %s VALUES (%s)" % (
insert_statement = "INSERT INTO {} VALUES ({})".format(
self.table,
",".join(["%s"] * len(columndefs)),
)
Expand All @@ -131,11 +131,11 @@ def generator(row, col):
self.assertEqual(res[i][j], generator(i, j))
delete_statement = "delete from %s where col1=%%s" % self.table
self.cursor.execute(delete_statement, (0,))
self.cursor.execute("select col1 from %s where col1=%s" % (self.table, 0))
self.cursor.execute(f"select col1 from {self.table} where col1=%s", (0,))
res = self.cursor.fetchall()
self.assertFalse(res, "DELETE didn't work")
self.connection.rollback()
self.cursor.execute("select col1 from %s where col1=%s" % (self.table, 0))
self.cursor.execute(f"select col1 from {self.table} where col1=%s", (0,))
res = self.cursor.fetchall()
self.assertTrue(len(res) == 1, "ROLLBACK didn't work")
self.cursor.execute("drop table %s" % (self.table))
Expand All @@ -150,7 +150,7 @@ def generator(row, col):
return ("%i" % (row % 10)) * ((255 - self.rows // 2) + row)

self.create_table(columndefs)
insert_statement = "INSERT INTO %s VALUES (%s)" % (
insert_statement = "INSERT INTO {} VALUES ({})".format(
self.table,
",".join(["%s"] * len(columndefs)),
)
Expand Down
3 changes: 1 addition & 2 deletions tests/dbapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ def _populate(self):
tests.
"""
populate = [
"insert into {}booze values ('{}')".format(self.table_prefix, s)
for s in self.samples
f"insert into {self.table_prefix}booze values ('{s}')" for s in self.samples
]
return populate

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def teardown_function(function):
c = _conns[0]
cur = c.cursor()
for t in _tables:
cur.execute("DROP TABLE {}".format(t))
cur.execute(f"DROP TABLE {t}")
cur.close()
del _tables[:]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def teardown_function(function):
c = _conns[0]
cur = c.cursor()
for t in _tables:
cur.execute("DROP TABLE {}".format(t))
cur.execute(f"DROP TABLE {t}")
cur.close()
del _tables[:]

Expand Down

0 comments on commit 1f906e6

Please sign in to comment.