Skip to content

Commit 7cc0e71

Browse files
committed
Fix: add typing about dict and improve docstring
1 parent 9bcf867 commit 7cc0e71

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ class ReportSlave(object):
4141
when connecting as a slave to a master. SHOW SLAVE HOSTS related.
4242
"""
4343

44-
def __init__(self, value: Union[str, Tuple[str, str, str, int]]) -> None:
44+
def __init__(self, value: Union[str, Tuple[str, str, str, int], Dict[str, Union[str, int]]]) -> None:
4545
"""
4646
Attributes:
47-
value: string or tuple
47+
value: string, tuple or dict
4848
if string, then it will be used hostname
4949
if tuple it will be used as (hostname, user, password, port)
50+
if dict, keys 'hostname', 'username', 'password', 'port' will be used.
5051
"""
5152
self.hostname: str = ''
5253
self.username: str = ''
@@ -342,7 +343,7 @@ def __connect_to_stream(self) -> None:
342343

343344
if not self.auto_position:
344345
if self.is_mariadb:
345-
prelude: ByteString = self.__set_mariadb_settings()
346+
prelude = self.__set_mariadb_settings()
346347
else:
347348
# only when log_file and log_pos both provided, the position info is
348349
# valid, if not, get the current position from master
@@ -355,7 +356,7 @@ def __connect_to_stream(self) -> None:
355356
self.log_file, self.log_pos = master_status[:2]
356357
cur.close()
357358

358-
prelude: ByteString = struct.pack('<i', len(self.log_file) + 11) \
359+
prelude: bytes = struct.pack('<i', len(self.log_file) + 11) \
359360
+ bytes(bytearray([COM_BINLOG_DUMP]))
360361

361362
if self.__resume_stream:
@@ -455,7 +456,7 @@ def __connect_to_stream(self) -> None:
455456
self._stream_connection._next_seq_id = 1
456457
self.__connected_stream: bool = True
457458

458-
def __set_mariadb_settings(self) -> ByteString:
459+
def __set_mariadb_settings(self) -> bytes:
459460
# https://mariadb.com/kb/en/5-slave-registration/
460461
cur: Cursor = self._stream_connection.cursor()
461462
if self.auto_position != None:
@@ -472,7 +473,7 @@ def __set_mariadb_settings(self) -> ByteString:
472473
4 # requested binlog file name , set it to empty
473474
)
474475

475-
prelude: ByteString = struct.pack('<i', header_size) + bytes(bytearray([COM_BINLOG_DUMP]))
476+
prelude: bytes = struct.pack('<i', header_size) + bytes(bytearray([COM_BINLOG_DUMP]))
476477

477478
# binlog pos
478479
prelude += struct.pack('<i', 4)

0 commit comments

Comments
 (0)