Add type hints to public APIs and configure mypy

- Improve mypy configuration with appropriate strictness settings
- Add comprehensive type hints to public API functions:
  - hookspecs.py: Type register_commands and prepare_connection hooks
  - plugins.py: Type get_plugins function and PluginManager
  - recipes.py: Type parsedate, parsedatetime, jsonsplit functions
  - utils.py: Type all public utility functions including rows_from_file,
    TypeTracker, ValueTracker, chunks, hash_record, flatten, etc.
  - db.py: Type Database, Queryable, Table, and View class methods
    including constructor, execute, query, table operations, etc.
- Exclude cli.py from strict checking (internal implementation detail)
- All public API modules now pass mypy type checking
This commit is contained in:
Claude 2025-12-15 18:57:58 +00:00
commit 83c50527aa
No known key found for this signature in database
6 changed files with 226 additions and 126 deletions

View file

@ -1,11 +1,18 @@
from typing import Any, Callable, Optional
from dateutil import parser
import json
IGNORE = object()
SET_NULL = object()
IGNORE: object = object()
SET_NULL: object = object()
def parsedate(value, dayfirst=False, yearfirst=False, errors=None):
def parsedate(
value: Optional[str],
dayfirst: bool = False,
yearfirst: bool = False,
errors: Optional[object] = None,
) -> Optional[str]:
"""
Parse a date and convert it to ISO date format: yyyy-mm-dd
\b
@ -31,7 +38,12 @@ def parsedate(value, dayfirst=False, yearfirst=False, errors=None):
raise
def parsedatetime(value, dayfirst=False, yearfirst=False, errors=None):
def parsedatetime(
value: Optional[str],
dayfirst: bool = False,
yearfirst: bool = False,
errors: Optional[object] = None,
) -> Optional[str]:
"""
Parse a datetime and convert it to ISO datetime format: yyyy-mm-ddTHH:MM:SS
\b
@ -53,7 +65,9 @@ def parsedatetime(value, dayfirst=False, yearfirst=False, errors=None):
raise
def jsonsplit(value, delimiter=",", type=str):
def jsonsplit(
value: str, delimiter: str = ",", type: Callable[[str], Any] = str
) -> str:
"""
Convert a string like a,b,c into a JSON array ["a", "b", "c"]
"""