Skip to content

refactor : eradicate formatted string #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pymysqlreplication/binlogstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def __init__(self, value):
self.hostname = value

def __repr__(self):
return "<ReportSlave hostname=%s username=%s password=%s port=%d>" % (
self.hostname,
self.username,
self.password,
self.port,
return (
f"<ReportSlave hostname={self.hostname} "
f"username={self.username} "
f"password={self.password} "
f"port={self.port}>"
)

def encoded(self, server_id, master_id=0):
Expand Down Expand Up @@ -367,7 +367,7 @@ def __connect_to_stream(self):
# master_heartbeat_period is nanoseconds
heartbeat = int(heartbeat * 1000000000)
cur = self._stream_connection.cursor()
cur.execute("SET @master_heartbeat_period= %d" % heartbeat)
cur.execute_with_args("SET @master_heartbeat_period= %d", (heartbeat,))
cur.close()

# When replicating from Mariadb 10.6.12 using binlog coordinates, a slave capability < 4 triggers a bug in
Expand Down
2 changes: 1 addition & 1 deletion pymysqlreplication/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)

def _dump(self):
super()._dump()
print(f"Schema: {self.schema}" % (self.schema))
print(f"Schema: {self.schema}")
print(f"Execution time: {self.execution_time}")
print(f"Query: {self.query}")

Expand Down
1 change: 0 additions & 1 deletion pymysqlreplication/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pymysql.protocol import MysqlPacket
import pytest


__all__ = [
"TestBasicBinLogStreamReader",
"TestMultipleRowBinLogStreamReader",
Expand Down
25 changes: 9 additions & 16 deletions pymysqlreplication/tests/test_data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,10 @@ def test_json_array(self):

def test_json_large(self):
data = dict(
[("foooo%i" % i, "baaaaar%i" % i) for i in range(2560)]
[(f"foooo{i}", f"baaaaar{i}") for i in range(2560)]
) # Make it large enough to reach 2^16 length
create_query = "CREATE TABLE test (id int, value json);"
insert_query = (
"""INSERT INTO test (id, value) VALUES (1, '%s');""" % json.dumps(data)
)
insert_query = f"INSERT INTO test (id, value) VALUES (1, '{json.dumps(data)}');"
event = self.create_and_insert_value(create_query, insert_query)
if event.table_map[event.table_id].column_name_flag:
self.assertEqual(event.rows[0]["values"]["value"], to_binary_dict(data))
Expand All @@ -621,8 +619,8 @@ def test_json_large_array(self):
"Test json array larger than 64k bytes"
create_query = "CREATE TABLE test (id int, value json);"
large_array = dict(my_key=[i for i in range(100000)])
insert_query = "INSERT INTO test (id, value) VALUES (1, '%s');" % (
json.dumps(large_array),
insert_query = (
f"INSERT INTO test (id, value) VALUES (1, '{json.dumps(large_array)}');"
)
event = self.create_and_insert_value(create_query, insert_query)
if event.table_map[event.table_id].column_name_flag:
Expand All @@ -632,12 +630,10 @@ def test_json_large_array(self):

def test_json_large_with_literal(self):
data = dict(
[("foooo%i" % i, "baaaaar%i" % i) for i in range(2560)], literal=True
[(f"foooo{i}", f"baaaaar{i}") for i in range(2560)], literal=True
) # Make it large with literal
create_query = "CREATE TABLE test (id int, value json);"
insert_query = (
"""INSERT INTO test (id, value) VALUES (1, '%s');""" % json.dumps(data)
)
insert_query = f"INSERT INTO test (id, value) VALUES (1, '{json.dumps(data)}');"
event = self.create_and_insert_value(create_query, insert_query)
if event.table_map[event.table_id].column_name_flag:
self.assertEqual(event.rows[0]["values"]["value"], to_binary_dict(data))
Expand All @@ -661,7 +657,7 @@ def test_json_types(self):
data = {"foo": t}
create_query = "CREATE TABLE test (id int, value json);"
insert_query = (
"""INSERT INTO test (id, value) VALUES (1, '%s');""" % json.dumps(data)
f"INSERT INTO test (id, value) VALUES (1, '{json.dumps(data)}');"
)
event = self.create_and_insert_value(create_query, insert_query)
if event.table_map[event.table_id].column_name_flag:
Expand All @@ -687,7 +683,7 @@ def test_json_basic(self):
for data in types:
create_query = "CREATE TABLE test (id int, value json);"
insert_query = (
"""INSERT INTO test (id, value) VALUES (1, '%s');""" % json.dumps(data)
f"INSERT INTO test (id, value) VALUES (1, '{json.dumps(data)}');"
)
event = self.create_and_insert_value(create_query, insert_query)
if event.table_map[event.table_id].column_name_flag:
Expand All @@ -709,10 +705,7 @@ def test_json_long_string(self):
create_query = "CREATE TABLE test (id int, value json);"
# The string length needs to be larger than what can fit in a single byte.
string_value = "super_long_string" * 100
insert_query = (
'INSERT INTO test (id, value) VALUES (1, \'{"my_key": "%s"}\');'
% (string_value,)
)
insert_query = f'INSERT INTO test (id, value) VALUES (1, \'{{"my_key": "{string_value}"}}\')'
event = self.create_and_insert_value(create_query, insert_query)
if event.table_map[event.table_id].column_name_flag:
self.assertEqual(
Expand Down