mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-10 11:24:11 +02:00
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:
parent
fd5b09f64b
commit
83c50527aa
6 changed files with 226 additions and 126 deletions
|
|
@ -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"]
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue