Skip to content

Commit 27a6e48

Browse files
committed
Refactoring version checks to be a static variable
Currently, the code has multiple instances where the pymysql version is checked inline with a vall to Version.py. This is unlikely to change during the duration of the script running so we can optimize by storing this in a variable once.
1 parent c952ced commit 27a6e48

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pymysqlreplication/binlogstream.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
# 2006 MySQL server has gone away
5252
MYSQL_EXPECTED_ERROR_CODES = [2013, 2006]
5353

54+
PYMYSQL_VERSION_LT_06 = Version(pymysql.__version__) < Version("0.6")
5455

5556
class ReportSlave(object):
5657
"""Represent the values that you may report when connecting as a slave
@@ -330,7 +331,7 @@ def _register_slave(self):
330331

331332
packet = self.report_slave.encoded(self.__server_id)
332333

333-
if Version(pymysql.__version__) < Version("0.6"):
334+
if PYMYSQL_VERSION_LT_06:
334335
self._stream_connection.wfile.write(packet)
335336
self._stream_connection.wfile.flush()
336337
self._stream_connection.read_packet()
@@ -502,7 +503,7 @@ def __connect_to_stream(self):
502503
# encoded_data
503504
prelude += gtid_set.encoded()
504505

505-
if Version(pymysql.__version__) < Version("0.6"):
506+
if PYMYSQL_VERSION_LT_06:
506507
self._stream_connection.wfile.write(prelude)
507508
self._stream_connection.wfile.flush()
508509
else:
@@ -588,7 +589,7 @@ def fetchone(self):
588589
self.__connect_to_ctl()
589590

590591
try:
591-
if Version(pymysql.__version__) < Version("0.6"):
592+
if PYMYSQL_VERSION_LT_06:
592593
pkt = self._stream_connection.read_packet()
593594
else:
594595
pkt = self._stream_connection._read_packet()

0 commit comments

Comments
 (0)