Skip to content

Commit 92ed19e

Browse files
committed
refctor(mypy): correct type errors
1 parent a86c7e9 commit 92ed19e

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import os
33
import sys
4+
import typing
45

56
from setuptools import find_packages, setup
67
from setuptools.command.install import install as InstallCommandBase
@@ -10,8 +11,8 @@
1011

1112

1213
class BasePytestCommand(TestCommand):
13-
user_options = []
14-
test_dir = None
14+
user_options: typing.List = []
15+
test_dir: typing.Optional[str] = None
1516

1617
def initialize_options(self):
1718
TestCommand.initialize_options(self)
@@ -34,7 +35,7 @@ def run_tests(self):
3435

3536

3637
class UnitTestCommand(BasePytestCommand):
37-
test_dir = "test/unit"
38+
test_dir: str = "test/unit"
3839

3940

4041
class IntegrationTestCommand(BasePytestCommand):
@@ -89,7 +90,7 @@ def get_tag(self):
8990

9091
setup(
9192
name="redshift_connector",
92-
version=__version__,
93+
version=__version__, # type: ignore
9394
description="Redshift interface library",
9495
long_description=long_description,
9596
long_description_content_type="text/x-rst",

test/integration/datatype/_generate_test_datatype_tables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Datatypes(Enum):
3939

4040
@classmethod
4141
def list(cls) -> typing.List["Datatypes"]:
42-
return list(map(lambda p: p, cls))
42+
return list(map(lambda p: p, cls)) # type: ignore
4343

4444

4545
FLOAT_DATATYPES: typing.Tuple[Datatypes, ...] = (Datatypes.float4, Datatypes.float8)
@@ -52,7 +52,7 @@ def list(cls) -> typing.List["Datatypes"]:
5252
# 3) (Optional) the Python value we expect to receive. If this field is missing,
5353
# we expect to receive the test value back directly.
5454

55-
test_data: typing.Dict[Datatypes, typing.Tuple[typing.Tuple[str, ...], ...]] = {
55+
test_data: typing.Dict[str, typing.Tuple[typing.Tuple[typing.Any, ...], ...]] = {
5656
Datatypes.int2.name: ( # smallint
5757
("-32768", -32768), # signed 2 byte int min
5858
("-128", -128),

test/integration/metadata/test_list_catalog.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class TestListCatalog:
7676
test_cross_db_schema_pattern: str = "p%"
7777
test_cross_db_table_pattern: str = "a%"
7878
test_cross_db_column_pattern: str = "c%"
79-
test_table_types: typing.Tuple[str] = ("TABLE", "SHARED TABLE", "VIEW", "EXTERNAL TABLE")
79+
test_table_types: typing.Tuple[str, ...] = ("TABLE", "SHARED TABLE", "VIEW", "EXTERNAL TABLE")
8080

8181
test_ext_schema: str = "ext_sales"
8282
test_ext_schema_table: str = "test"
@@ -163,12 +163,12 @@ def test_get_schemas(mocker, _input, db_kwargs):
163163
assert len(result[0]) == 2
164164

165165

166-
def get_tables_test_data() -> typing.List[typing.Tuple[bool, typing.Dict[str, typing.Optional[str]]]]:
167-
result: typing.List[typing.Tuple[bool, typing.Dict[str, typing.Optional[str]]]] = []
166+
def get_tables_test_data() -> typing.List[typing.Optional[typing.Tuple[bool, typing.Dict[str, typing.Any]]]]:
167+
result: typing.List[typing.Optional[typing.Tuple[bool, typing.Dict[str, typing.Any]]]] = []
168168
for flip in (True, False):
169169
TestListCatalog.config_class_consts(flip)
170-
arg_data: typing.List[typing.Dict[str, typing.Optional[str]]] = [
171-
{"catalog": None, "schema_pattern": None, "table_name_pattern": None, "types": []},
170+
arg_data: typing.List[typing.Dict[str, typing.Any]] = [
171+
{"catalog": None, "schema_pattern": None, "table_name_pattern": None, "types": tuple()},
172172
{
173173
"catalog": TestListCatalog.test_db,
174174
"schema_pattern": TestListCatalog.test_schema,
@@ -197,7 +197,7 @@ def get_tables_test_data() -> typing.List[typing.Tuple[bool, typing.Dict[str, ty
197197
"catalog": TestListCatalog.test_db,
198198
"schema_pattern": TestListCatalog.test_schema,
199199
"table_name_pattern": TestListCatalog.test_table,
200-
"types": [],
200+
"types": tuple(),
201201
},
202202
{
203203
"catalog": None,
@@ -215,15 +215,20 @@ def get_tables_test_data() -> typing.List[typing.Tuple[bool, typing.Dict[str, ty
215215
"catalog": TestListCatalog.test_db,
216216
"schema_pattern": TestListCatalog.test_schema,
217217
"table_name_pattern": None,
218-
"types": [],
218+
"types": tuple(),
219219
},
220220
{
221221
"catalog": None,
222222
"schema_pattern": TestListCatalog.test_schema,
223223
"table_name_pattern": TestListCatalog.test_table,
224-
"types": [],
224+
"types": tuple(),
225+
},
226+
{
227+
"catalog": None,
228+
"schema_pattern": None,
229+
"table_name_pattern": TestListCatalog.test_table,
230+
"types": tuple(),
225231
},
226-
{"catalog": None, "schema_pattern": None, "table_name_pattern": TestListCatalog.test_table, "types": []},
227232
{
228233
"catalog": None,
229234
"schema_pattern": None,
@@ -252,7 +257,7 @@ def get_tables_test_data() -> typing.List[typing.Tuple[bool, typing.Dict[str, ty
252257
"catalog": None,
253258
"schema_pattern": TestListCatalog.test_schema_pattern,
254259
"table_name_pattern": TestListCatalog.test_table_pattern,
255-
"types": [],
260+
"types": tuple(),
256261
},
257262
]
258263
for test_case in arg_data:

test/performance/performance.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import configparser
22
import os
33
import time
4+
import typing
45

56
import redshift_connector
67

@@ -9,12 +10,12 @@
910
conf.read(root_path + "/config.ini")
1011

1112
root_path = os.path.dirname(os.path.abspath(__file__))
12-
sql = open(root_path + "/test.sql", "r", encoding="utf8")
13-
sqls = sql.readlines()
14-
sqls = [sql.replace("\n", "") for sql in sqls]
13+
sql: typing.TextIO = open(root_path + "/test.sql", "r", encoding="utf8")
14+
sqls: typing.List[str] = sql.readlines()
15+
sqls = [_sql.replace("\n", "") for _sql in sqls]
1516
sql.close()
1617

17-
conn = redshift_connector.connect(
18+
conn: redshift_connector.Connection = redshift_connector.connect(
1819
database=conf.get("database", "database"),
1920
host=conf.get("database", "host"),
2021
port=conf.getint("database", "port"),
@@ -25,11 +26,11 @@
2526
iam=False,
2627
)
2728

28-
cursor = conn.cursor()
29-
for sql in sqls:
30-
cursor.execute(sql)
29+
cursor: redshift_connector.Cursor = conn.cursor()
30+
for _sql in sqls:
31+
cursor.execute(_sql)
3132

32-
result = cursor.fetchall()
33+
result: typing.Tuple = cursor.fetchall()
3334
print("fetch {result} rows".format(result=result))
3435

3536
print("start calculate fetch time")

0 commit comments

Comments
 (0)