Skip to content

Commit ec8d8fd

Browse files
committed
add: type hints for PyMyReplTestCase
1 parent 89d34bb commit ec8d8fd

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pymysqlreplication/tests/base.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
from pymysql.cursors import Cursor
77
import pymysql
8+
from pymysql import Connection
9+
from typing import Optional
810

911
from pymysqlreplication import BinLogStreamReader
1012

@@ -22,7 +24,7 @@ def ignoredEvents(self) -> list:
2224

2325
def setUp(self) -> None:
2426
# default
25-
self.database = {
27+
self.database: dict = {
2628
"host": os.environ.get("MYSQL_5_7") or "localhost",
2729
"user": "root",
2830
"passwd": "",
@@ -32,18 +34,18 @@ def setUp(self) -> None:
3234
"db": "pymysqlreplication_test",
3335
}
3436

35-
self.conn_control = None
37+
self.conn_control: Optional[Connection] = None
3638
db = copy.copy(self.database)
3739
db["db"] = None
3840
self.connect_conn_control(db)
3941
self.execute("DROP DATABASE IF EXISTS pymysqlreplication_test")
4042
self.execute("CREATE DATABASE pymysqlreplication_test")
4143
db = copy.copy(self.database)
4244
self.connect_conn_control(db)
43-
self.stream = None
45+
self.stream: Optional[BinLogStreamReader] = None
4446
self.resetBinLog()
4547
self.isMySQL56AndMore()
46-
self.__is_mariaDB = None
48+
self.__is_mariaDB: Optional[bool] = None
4749

4850
def getMySQLVersion(self) -> str:
4951
"""Return the MySQL version of the server
@@ -67,7 +69,7 @@ def isMySQL80AndMore(self) -> bool:
6769

6870
def isMariaDB(self) -> bool:
6971
if self.__is_mariaDB is None:
70-
self.__is_mariaDB = (
72+
self.__is_mariaDB: bool = (
7173
"MariaDB" in self.execute("SELECT VERSION()").fetchone()[0]
7274
)
7375
return self.__is_mariaDB
@@ -81,13 +83,13 @@ def supportsGTID(self) -> bool:
8183
def connect_conn_control(self, db) -> None:
8284
if self.conn_control is not None:
8385
self.conn_control.close()
84-
self.conn_control = pymysql.connect(**db)
86+
self.conn_control: Connection = pymysql.connect(**db)
8587

8688
def tearDown(self) -> None:
8789
self.conn_control.close()
88-
self.conn_control = None
90+
self.conn_control: Optional[Connection] = None
8991
self.stream.close()
90-
self.stream = None
92+
self.stream: Optional[BinLogStreamReader] = None
9193

9294
def execute(self, query: str) -> Cursor:
9395
c = self.conn_control.cursor()
@@ -103,7 +105,7 @@ def resetBinLog(self) -> None:
103105
self.execute("RESET MASTER")
104106
if self.stream is not None:
105107
self.stream.close()
106-
self.stream = BinLogStreamReader(
108+
self.stream: BinLogStreamReader = BinLogStreamReader(
107109
self.database, server_id=1024, ignored_events=self.ignoredEvents()
108110
)
109111

@@ -139,15 +141,15 @@ def setUp(self) -> None:
139141
"db": "pymysqlreplication_test",
140142
}
141143

142-
self.conn_control = None
144+
self.conn_control: Optional[Connection] = None
143145
db = copy.copy(self.database)
144146
db["db"] = None
145147
self.connect_conn_control(db)
146148
self.execute("DROP DATABASE IF EXISTS pymysqlreplication_test")
147149
self.execute("CREATE DATABASE pymysqlreplication_test")
148150
db = copy.copy(self.database)
149151
self.connect_conn_control(db)
150-
self.stream = None
152+
self.stream: Optional[BinLogStreamReader] = None
151153
self.resetBinLog()
152154

153155
def bin_log_basename(self) -> str:

0 commit comments

Comments
 (0)