Skip to content

Commit a3bd19a

Browse files
committed
🏷️ add types
1 parent 9f6db94 commit a3bd19a

File tree

10 files changed

+319
-153
lines changed

10 files changed

+319
-153
lines changed

mysql_to_sqlite3/cli.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""The command line interface of MySQLtoSQLite."""
2+
import os
23
import sys
4+
import typing as t
35

46
import click
57
from tabulate import tabulate
@@ -115,29 +117,29 @@
115117
@click.option("--debug", is_flag=True, help="Debug mode. Will throw exceptions.")
116118
@click.version_option(message=tabulate(info(), headers=["software", "version"], tablefmt="github"))
117119
def cli(
118-
sqlite_file,
119-
mysql_user,
120-
prompt_mysql_password,
121-
mysql_password,
122-
mysql_database,
123-
mysql_tables,
124-
exclude_mysql_tables,
125-
limit_rows,
126-
collation,
127-
prefix_indices,
128-
without_foreign_keys,
129-
without_data,
130-
mysql_host,
131-
mysql_port,
132-
skip_ssl,
133-
chunk,
134-
log_file,
135-
json_as_text,
136-
vacuum,
137-
use_buffered_cursors,
138-
quiet,
139-
debug,
140-
):
120+
sqlite_file: t.Union[str, "os.PathLike[t.Any]"],
121+
mysql_user: str,
122+
prompt_mysql_password: bool,
123+
mysql_password: str,
124+
mysql_database: str,
125+
mysql_tables: t.Optional[t.Sequence[str]],
126+
exclude_mysql_tables: t.Optional[t.Sequence[str]],
127+
limit_rows: int,
128+
collation: t.Optional[str],
129+
prefix_indices: bool,
130+
without_foreign_keys: bool,
131+
without_data: bool,
132+
mysql_host: str,
133+
mysql_port: int,
134+
skip_ssl: bool,
135+
chunk: int,
136+
log_file: t.Union[str, "os.PathLike[t.Any]"],
137+
json_as_text: bool,
138+
vacuum: bool,
139+
use_buffered_cursors: bool,
140+
quiet: bool,
141+
debug: bool,
142+
) -> None:
141143
"""Transfer MySQL to SQLite using the provided CLI options."""
142144
try:
143145
if mysql_tables and exclude_mysql_tables:

mysql_to_sqlite3/click_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Click utilities."""
22

3+
import typing as t
4+
35
import click
46

57

@@ -16,7 +18,7 @@ def __init__(self, *args, **kwargs):
1618
self._previous_parser_process = None
1719
self._eat_all_parser = None
1820

19-
def add_to_parser(self, parser, ctx):
21+
def add_to_parser(self, parser, ctx) -> None:
2022
"""Override."""
2123

2224
def parser_process(value, state):
@@ -52,7 +54,7 @@ def parser_process(value, state):
5254
return retval
5355

5456

55-
def prompt_password(ctx, param, use_password): # pylint: disable=W0613
57+
def prompt_password(ctx: click.core.Context, param: t.Any, use_password: bool): # pylint: disable=W0613
5658
"""Prompt for password."""
5759
if use_password:
5860
mysql_password = ctx.params.get("mysql_password")
@@ -62,7 +64,7 @@ def prompt_password(ctx, param, use_password): # pylint: disable=W0613
6264
return mysql_password
6365

6466

65-
def validate_positive_integer(ctx, param, value): # pylint: disable=W0613
67+
def validate_positive_integer(ctx: click.core.Context, param: t.Any, value: int): # pylint: disable=W0613
6668
"""Allow only positive integers and 0."""
6769
if value < 0:
6870
raise click.BadParameter("Should be a positive integer or 0.")

mysql_to_sqlite3/debug_info.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import platform
77
import sqlite3
88
import sys
9+
import typing as t
910
from distutils.spawn import find_executable # pylint: disable=W0402
1011
from subprocess import check_output
1112

@@ -20,7 +21,7 @@
2021
from . import __version__ as package_version
2122

2223

23-
def _implementation():
24+
def _implementation() -> str:
2425
"""Return a dict with the Python implementation and version.
2526
2627
Provide both the name and the version of the Python implementation
@@ -31,17 +32,17 @@ def _implementation():
3132
doesn't work for Jython or IronPython. Future investigation should be done
3233
to work out the correct shape of the code for those platforms.
3334
"""
34-
implementation = platform.python_implementation()
35+
implementation: str = platform.python_implementation()
3536

3637
if implementation == "CPython":
3738
implementation_version = platform.python_version()
3839
elif implementation == "PyPy":
3940
implementation_version = "%s.%s.%s" % (
40-
sys.pypy_version_info.major, # noqa: ignore=E1101 pylint: disable=E1101
41-
sys.pypy_version_info.minor, # noqa: ignore=E1101 pylint: disable=E1101
42-
sys.pypy_version_info.micro, # noqa: ignore=E1101 pylint: disable=E1101
41+
sys.pypy_version_info.major, # type: ignore # noqa: ignore=E1101 pylint: disable=E1101
42+
sys.pypy_version_info.minor, # type: ignore # noqa: ignore=E1101 pylint: disable=E1101
43+
sys.pypy_version_info.micro, # type: ignore # noqa: ignore=E1101 pylint: disable=E1101
4344
)
44-
rel = sys.pypy_version_info.releaselevel # noqa: ignore=E1101 pylint: disable=E1101
45+
rel = sys.pypy_version_info.releaselevel # type: ignore # noqa: ignore=E1101 pylint: disable=E1101
4546
if rel != "final":
4647
implementation_version = "".join([implementation_version, rel])
4748
elif implementation == "Jython":
@@ -56,23 +57,23 @@ def _implementation():
5657
)
5758

5859

59-
def _mysql_version():
60+
def _mysql_version() -> str:
6061
if find_executable("mysql"):
6162
try:
62-
mysql_version = check_output(["mysql", "-V"])
63+
mysql_version: t.Union[str, bytes] = check_output(["mysql", "-V"])
6364
try:
64-
return mysql_version.decode().strip()
65+
return mysql_version.decode().strip() # type: ignore
6566
except (UnicodeDecodeError, AttributeError):
66-
return mysql_version
67+
return str(mysql_version)
6768
except Exception: # nosec pylint: disable=W0703
6869
pass
6970
return "MySQL client not found on the system"
7071

7172

72-
def info():
73+
def info() -> t.List[t.List[str]]:
7374
"""Generate information for a bug report."""
7475
try:
75-
platform_info = "{system} {release}".format(
76+
platform_info: str = "{system} {release}".format(
7677
system=platform.system(),
7778
release=platform.release(),
7879
)
@@ -91,7 +92,7 @@ def info():
9192
["mysql-connector-python", mysql.connector.__version__],
9293
["python-slugify", slugify.__version__],
9394
["pytimeparse2", pytimeparse2.__version__],
94-
["simplejson", simplejson.__version__],
95+
["simplejson", simplejson.__version__], # type: ignore
9596
["tabulate", tabulate.__version__],
9697
["tqdm", tqdm.__version__],
9798
]

mysql_to_sqlite3/py.typed

Whitespace-only changes.

mysql_to_sqlite3/sqlite_utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
"""SQLite adapters and converters for unsupported data types."""
22

33
import sqlite3
4+
import typing as t
45
from datetime import date, timedelta
56
from decimal import Decimal
67

78
from pytimeparse2 import parse
89

910

10-
def adapt_decimal(value):
11+
def adapt_decimal(value: t.Any) -> str:
1112
"""Convert decimal.Decimal to string."""
1213
return str(value)
1314

1415

15-
def convert_decimal(value):
16-
"""Convert string to decimalDecimal."""
16+
def convert_decimal(value: t.Any) -> Decimal:
17+
"""Convert string to decimal.Decimal."""
1718
return Decimal(value)
1819

1920

20-
def adapt_timedelta(value):
21+
def adapt_timedelta(value: t.Any) -> str:
2122
"""Convert datetime.timedelta to %H:%M:%S string."""
2223
hours, remainder = divmod(value.total_seconds(), 3600)
2324
minutes, seconds = divmod(remainder, 60)
2425
return "{:02}:{:02}:{:02}".format(int(hours), int(minutes), int(seconds))
2526

2627

27-
def convert_timedelta(value):
28+
def convert_timedelta(value: t.Any) -> timedelta:
2829
"""Convert %H:%M:%S string to datetime.timedelta."""
2930
return timedelta(seconds=parse(value))
3031

3132

32-
def encode_data_for_sqlite(value):
33+
def encode_data_for_sqlite(value: t.Any) -> t.Any:
3334
"""Fix encoding bytes."""
3435
try:
3536
return value.decode()
@@ -40,12 +41,12 @@ def encode_data_for_sqlite(value):
4041
class CollatingSequences:
4142
"""Taken from https://www.sqlite.org/datatype3.html#collating_sequences."""
4243

43-
BINARY = "BINARY"
44-
NOCASE = "NOCASE"
45-
RTRIM = "RTRIM"
44+
BINARY: str = "BINARY"
45+
NOCASE: str = "NOCASE"
46+
RTRIM: str = "RTRIM"
4647

4748

48-
def convert_date(value):
49+
def convert_date(value: t.Any) -> date:
4950
"""Handle SQLite date conversion."""
5051
try:
5152
return date.fromisoformat(value.decode())

0 commit comments

Comments
 (0)