From 1f906e66c4082c305645ddcded18018cecc302fd Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 9 May 2023 14:10:53 +0900 Subject: [PATCH] Run pyupgrade --py38-plus (#590) --- MySQLdb/connections.py | 2 +- MySQLdb/constants/CR.py | 2 +- MySQLdb/constants/ER.py | 2 +- setup_common.py | 2 +- tests/capabilities.py | 14 +++++++------- tests/dbapi20.py | 3 +-- tests/test_cursor.py | 2 +- tests/test_errors.py | 2 +- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index f56c4f54..865d129a 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -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): diff --git a/MySQLdb/constants/CR.py b/MySQLdb/constants/CR.py index 9d33cf65..9467ae11 100644 --- a/MySQLdb/constants/CR.py +++ b/MySQLdb/constants/CR.py @@ -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) diff --git a/MySQLdb/constants/ER.py b/MySQLdb/constants/ER.py index fcd5bf2e..8c5ece24 100644 --- a/MySQLdb/constants/ER.py +++ b/MySQLdb/constants/ER.py @@ -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) diff --git a/setup_common.py b/setup_common.py index 8d7a37d5..53869aa2 100644 --- a/setup_common.py +++ b/setup_common.py @@ -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): diff --git a/tests/capabilities.py b/tests/capabilities.py index 034e88da..1e695e9e 100644 --- a/tests/capabilities.py +++ b/tests/capabilities.py @@ -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 ) @@ -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)), ) @@ -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)), ) @@ -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)) @@ -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)), ) diff --git a/tests/dbapi20.py b/tests/dbapi20.py index a88a0616..be0f6292 100644 --- a/tests/dbapi20.py +++ b/tests/dbapi20.py @@ -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 diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 91f0323e..80e21888 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -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[:] diff --git a/tests/test_errors.py b/tests/test_errors.py index 3a9fecaa..fae28e81 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -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[:]