From 325d1949c186f7e104dfbb0edd42a96cefe9f015 Mon Sep 17 00:00:00 2001 From: Pilmo Date: Tue, 29 Aug 2023 21:59:55 +0900 Subject: [PATCH 1/6] Add type in bitmap.py --- pymysqlreplication/bitmap.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pymysqlreplication/bitmap.py b/pymysqlreplication/bitmap.py index fd2096b6..54096dea 100644 --- a/pymysqlreplication/bitmap.py +++ b/pymysqlreplication/bitmap.py @@ -1,6 +1,8 @@ +from typing import List + # -*- coding: utf-8 -*- -bitCountInByte = [ +bitCountInByte: List[int] = [ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, @@ -19,18 +21,21 @@ 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, ] + # Calculate total bit counts in a bitmap -def BitCount(bitmap): +def BitCount(bitmap: bytes) -> int: n = 0 for i in range(0, len(bitmap)): bit = bitmap[i] if type(bit) is str: bit = ord(bit) n += bitCountInByte[bit] + return n + # Get the bit set at offset position in bitmap -def BitGet(bitmap, position): +def BitGet(bitmap: bytes, position: int) -> int: bit = bitmap[int(position / 8)] if type(bit) is str: bit = ord(bit) From aceab8b9d32c311e2317f5310f92d9b15381212f Mon Sep 17 00:00:00 2001 From: will-k Date: Wed, 30 Aug 2023 00:13:56 +0900 Subject: [PATCH 2/6] Add type annotations to test_data_type.py --- pymysqlreplication/tests/test_data_type.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pymysqlreplication/tests/test_data_type.py b/pymysqlreplication/tests/test_data_type.py index cd6464c5..7a8a917f 100644 --- a/pymysqlreplication/tests/test_data_type.py +++ b/pymysqlreplication/tests/test_data_type.py @@ -34,7 +34,7 @@ class TestDataType(base.PyMySQLReplicationTestCase): def ignoredEvents(self): return [GtidEvent] - def create_and_insert_value(self, create_query, insert_query): + def create_and_insert_value(self, create_query: str, insert_query: str): self.execute(create_query) self.execute(insert_query) self.execute("COMMIT") @@ -57,7 +57,7 @@ def create_and_insert_value(self, create_query, insert_query): self.assertIsInstance(event, WriteRowsEvent) return event - def create_table(self, create_query): + def create_table(self, create_query: str): """Create table Create table in db and return query event. @@ -77,7 +77,7 @@ def create_table(self, create_query): return event - def create_and_get_tablemap_event(self, bit): + def create_and_get_tablemap_event(self): """Create table and return tablemap event Returns: From 3e76aeda4dff239ec1e36472daebbeb23f1b2f5a Mon Sep 17 00:00:00 2001 From: "cucuridas@gamil.com" <3310223@naver.com> Date: Wed, 30 Aug 2023 22:44:50 +0900 Subject: [PATCH 3/6] Add type annotations to test_data_objects.py --- pymysqlreplication/tests/test_data_objects.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymysqlreplication/tests/test_data_objects.py b/pymysqlreplication/tests/test_data_objects.py index dc1281c3..fff03e80 100644 --- a/pymysqlreplication/tests/test_data_objects.py +++ b/pymysqlreplication/tests/test_data_objects.py @@ -9,12 +9,13 @@ from pymysqlreplication.event import GtidEvent from pymysqlreplication.tests import base +from typing import List __all__ = ["TestDataObjects"] class TestDataObjects(base.PyMySQLReplicationTestCase): - def ignoredEvents(self): + def ignoredEvents(self) -> List[GtidEvent]: return [GtidEvent] def test_column_is_primary(self): From 28880c61eb50ac5a4fece40502bb9221a97839df Mon Sep 17 00:00:00 2001 From: BeautterLife Date: Wed, 30 Aug 2023 23:15:46 +0900 Subject: [PATCH 4/6] Add type annotations to table.py --- pymysqlreplication/table.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pymysqlreplication/table.py b/pymysqlreplication/table.py index ed473cd6..3381a477 100644 --- a/pymysqlreplication/table.py +++ b/pymysqlreplication/table.py @@ -1,8 +1,13 @@ # -*- coding: utf-8 -*- +from typing import List +from typing import Dict +from typing import Optional +from column import Column class Table(object): - def __init__(self, column_schemas, table_id, schema, table, columns, primary_key=None): + def __init__(self, column_schemas: List[Dict[str, str]], table_id: int, schema: str, table: str, + columns: List[Column], primary_key: Optional[List[str]]): if primary_key is None: primary_key = [c.data["name"] for c in columns if c.data["is_primary"]] if len(primary_key) == 0: @@ -25,11 +30,11 @@ def __init__(self, column_schemas, table_id, schema, table, columns, primary_key def data(self): return dict((k, v) for (k, v) in self.__dict__.items() if not k.startswith('_')) - def __eq__(self, other): + def __eq__(self, other: 'Table') -> bool: return self.data == other.data - def __ne__(self, other): + def __ne__(self, other: 'Table') -> bool: return not self.__eq__(other) - def serializable_data(self): + def serializable_data(self) -> 'Table': return self.data From 5c12e1a559ff438c691937991f4452d5480ab9d7 Mon Sep 17 00:00:00 2001 From: BeautterLife Date: Wed, 30 Aug 2023 23:22:23 +0900 Subject: [PATCH 5/6] Fix module path --- pymysqlreplication/table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysqlreplication/table.py b/pymysqlreplication/table.py index 3381a477..b9619414 100644 --- a/pymysqlreplication/table.py +++ b/pymysqlreplication/table.py @@ -2,7 +2,7 @@ from typing import List from typing import Dict from typing import Optional -from column import Column +from pymysqlreplication.column import Column class Table(object): From 4d34f17e2dcf90e069270945f5a63a6b60552749 Mon Sep 17 00:00:00 2001 From: BeautterLife Date: Wed, 30 Aug 2023 23:31:27 +0900 Subject: [PATCH 6/6] Assign default value of primay_key as None --- pymysqlreplication/table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysqlreplication/table.py b/pymysqlreplication/table.py index b9619414..3e34c169 100644 --- a/pymysqlreplication/table.py +++ b/pymysqlreplication/table.py @@ -7,7 +7,7 @@ class Table(object): def __init__(self, column_schemas: List[Dict[str, str]], table_id: int, schema: str, table: str, - columns: List[Column], primary_key: Optional[List[str]]): + columns: List[Column], primary_key: Optional[List[str]] = None): if primary_key is None: primary_key = [c.data["name"] for c in columns if c.data["is_primary"]] if len(primary_key) == 0: