Skip to content

Commit 3eaafb7

Browse files
committed
typehint some of main.py, with fixes elsewhere
* typehint >80% of main.py * requiring additional hints and fixes in config.py, sqlexecute.py, packages/parseutils.py, and others * typehint unhinted portions of sqlexecute.py * remove @export decorator and import explicitly into "special" * recast some uninformative variable names * assert that a connection is available before using it * take more care with: ssl config, port, and ssh_port types/defaults before creating a connection * local_infile is a boolean, not a string * ensure get_password_from_file() returns a value * assert that a PromptSession is available before invoking methods on it * set a fallback col/row size in case a prompt session is not available * declare and type self.conn in SQLExecute much earlier * take more care to distinguish falsey values from Nones in SQLExecute connect() * improve defaults passed to pymysql.connect(), matching them to the pymysql docs * test that self.conn is not None rather than checking for a "conn" attribute, before invoking close() * remove Python 2.x-compat Unicode literals trick for click * better catch empty database names in change_db() * take more care for edge-case values of text in one_iteration() * don't return None for connection_id_to_kill * clarify overlapping "e" variables * don't use self.sqlexecute when sqlexecute is already available * is_dropping_database() takes a string, not a list * typehint unhinted function in packages/parseutils.py * update changelog
1 parent b3385a1 commit 3eaafb7

File tree

10 files changed

+327
-239
lines changed

10 files changed

+327
-239
lines changed

changelog.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
Unreleased
1+
Upcoming Release (TBD)
2+
======================
3+
4+
Internal
5+
--------
6+
* Continue typehinting the non-test codebase.
7+
8+
9+
1.37.1 (2025/07/28)
210
======================
311

412
Internal
@@ -7,6 +15,7 @@ Internal
715
* Align LICENSE with SPDX format.
816
* Fix deprecated `license` specification format in `pyproject.toml`.
917

18+
1019
1.37.0 (2025/07/28)
1120
======================
1221

mycli/clibuffer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from typing import Callable
1+
from __future__ import annotations
22

33
from prompt_toolkit.application import get_app
44
from prompt_toolkit.enums import DEFAULT_BUFFER
5-
from prompt_toolkit.filters import Condition
5+
from prompt_toolkit.filters import Condition, Filter
66

77
from mycli.packages.special import iocommands
88

99

10-
def cli_is_multiline(mycli) -> Callable:
10+
def cli_is_multiline(mycli) -> Filter:
1111
@Condition
1212
def cond():
1313
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document

mycli/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from os.path import exists
99
import struct
1010
import sys
11-
from typing import IO, BinaryIO, Literal
11+
from typing import IO, BinaryIO, Literal, TextIO
1212

1313
from configobj import ConfigObj, ConfigObjError
1414
import pyaes
@@ -25,7 +25,7 @@ def log(logger: logging.Logger, level: int, message: str) -> None:
2525
logger.log(level, message)
2626

2727

28-
def read_config_file(f: str | TextIOWrapper, list_values: bool = True) -> ConfigObj | None:
28+
def read_config_file(f: str | TextIO | TextIOWrapper, list_values: bool = True) -> ConfigObj | None:
2929
"""Read a config file.
3030
3131
*list_values* set to `True` is the default behavior of ConfigObj.
@@ -52,7 +52,7 @@ def read_config_file(f: str | TextIOWrapper, list_values: bool = True) -> Config
5252
return config
5353

5454

55-
def get_included_configs(config_file: str | TextIOWrapper) -> list[str]:
55+
def get_included_configs(config_file: str | TextIOWrapper) -> list[str | TextIOWrapper]:
5656
"""Get a list of configuration files that are included into config_path
5757
with !includedir directive.
5858
@@ -64,7 +64,7 @@ def get_included_configs(config_file: str | TextIOWrapper) -> list[str]:
6464
"""
6565
if not isinstance(config_file, str) or not os.path.isfile(config_file):
6666
return []
67-
included_configs = []
67+
included_configs: list[str | TextIOWrapper] = []
6868

6969
try:
7070
with open(config_file) as f:
@@ -80,7 +80,7 @@ def get_included_configs(config_file: str | TextIOWrapper) -> list[str]:
8080
return included_configs
8181

8282

83-
def read_config_files(files: list[str], list_values: bool = True) -> ConfigObj:
83+
def read_config_files(files: list[str | TextIOWrapper], list_values: bool = True) -> ConfigObj:
8484
"""Read and merge a list of config files."""
8585

8686
config = create_default_config(list_values=list_values)

0 commit comments

Comments
 (0)