mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all 191 'no-untyped-def' mypy errors in strict mode. The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch, Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session, rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult, and all db/schema files (Column, Table, ColumnSet, DataType, Schema, SingleForeignKey, CompositeForeignKey), plus asyncio variants and ev/base/Object and auth/dummy/Auth. Additionally, unreachable code and type annotation conflicts were resolved in StopWatch.py, Options.py, rows.py, and Table.py. Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
73f52fb609
commit
9323529187
1 changed files with 247 additions and 220 deletions
|
|
@ -4,7 +4,7 @@ import shlex
|
|||
import traceback
|
||||
|
||||
from collections import OrderedDict
|
||||
from typing import override
|
||||
from typing import Any, override
|
||||
|
||||
from .log import ERR, get_caller_pos, slog, slog_m
|
||||
|
||||
|
|
@ -12,21 +12,21 @@ class Options: # export
|
|||
|
||||
class OrderedData:
|
||||
|
||||
def __init__(self, pairs = None):
|
||||
def __init__(self, pairs: list[tuple[str, str]] | None = None) -> None:
|
||||
self.__pairs = [] if pairs is None else pairs
|
||||
|
||||
def add(self, lhs, rhs):
|
||||
def add(self, lhs: str, rhs: str) -> None:
|
||||
self.__pairs.append((lhs, rhs))
|
||||
|
||||
def dump(self):
|
||||
def dump(self) -> None:
|
||||
for p in self.__pairs:
|
||||
print(p)
|
||||
|
||||
@property
|
||||
def pairs(self):
|
||||
def pairs(self) -> list[tuple[str, str]]:
|
||||
return self.__pairs
|
||||
|
||||
def __parse_json(self, spec, cls):
|
||||
def __parse_json(self, spec: str, cls: Any) -> Any:
|
||||
spec = spec.strip()
|
||||
if len(spec) < 3:
|
||||
return None
|
||||
|
|
@ -38,7 +38,7 @@ class Options: # export
|
|||
pass
|
||||
return None
|
||||
|
||||
def __parse(self, opts_str, cls):
|
||||
def __parse(self, opts_str: str, cls: Any) -> Any:
|
||||
r = self.__parse_json(opts_str, cls)
|
||||
if r is not None:
|
||||
return r
|
||||
|
|
@ -64,7 +64,7 @@ class Options: # export
|
|||
r.add(lhs, rhs)
|
||||
return r
|
||||
|
||||
def __recache(self):
|
||||
def __recache(self) -> None:
|
||||
self.__list.clear()
|
||||
self.__dict.clear()
|
||||
for key, val in self.__data.pairs:
|
||||
|
|
@ -82,29 +82,29 @@ class Options: # export
|
|||
else:
|
||||
cur = [cur, val]
|
||||
self.__dict[key] = cur
|
||||
self.__str = self.__str__()
|
||||
self.__str_cache = self.__str__()
|
||||
|
||||
def __getitem__(self, key):
|
||||
def __getitem__(self, key: str) -> Any:
|
||||
if key not in self.__dict.keys():
|
||||
return None
|
||||
return self.__dict[key]
|
||||
|
||||
@override
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
return ', '.join(str(p[0]) + ': ' + str(p[1]) for p in self.__data.pairs)
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return self.__str__()
|
||||
|
||||
@override
|
||||
def __format__(self, fmt):
|
||||
def __format__(self, fmt: str) -> str:
|
||||
return self.__str__()
|
||||
|
||||
def __len__(self):
|
||||
def __len__(self) -> int:
|
||||
return len(self.__data.pairs)
|
||||
|
||||
def __contains__(self, keys):
|
||||
def __contains__(self, keys: Any) -> bool:
|
||||
if type(keys) not in [list, set]:
|
||||
return keys in self.__dict.keys()
|
||||
for key in keys:
|
||||
|
|
@ -112,54 +112,61 @@ class Options: # export
|
|||
return False
|
||||
return True
|
||||
|
||||
def __iter__(self):
|
||||
def __iter__(self) -> Any:
|
||||
return iter(self.__list)
|
||||
|
||||
#def __next__(self):
|
||||
# return next(self.__list)
|
||||
|
||||
def __init__(
|
||||
self, spec = None, delimiter = ',', allowed_keys = None, true_val = True
|
||||
):
|
||||
self,
|
||||
spec: Any = None,
|
||||
delimiter: str = ',',
|
||||
allowed_keys: Any = None,
|
||||
true_val: Any = True
|
||||
) -> None:
|
||||
self.__true_val = true_val
|
||||
self.__allowed_keys = None
|
||||
self.__delimiter = delimiter
|
||||
self.__data = self.OrderedData(
|
||||
) if spec is None else self.__parse(spec, self.OrderedData)
|
||||
self.__dict = {}
|
||||
self.__data = (
|
||||
self.__class__.OrderedData()
|
||||
if spec is None else self.__parse(spec, self.__class__.OrderedData)
|
||||
)
|
||||
self.__dict: dict[str, Any] = {}
|
||||
#self.__dict = OrderedDict() if spec is None else self.__parse(spec,OrderedDict)
|
||||
self.__list = []
|
||||
self.__str = None
|
||||
self.__list: list[str] = []
|
||||
self.__str_cache = None # type: ignore[assignment]
|
||||
self.__recache()
|
||||
|
||||
def dump(self, prio, caller = None):
|
||||
def dump(self, prio: int, caller: Any = None) -> None:
|
||||
if caller is None:
|
||||
caller = get_caller_pos()
|
||||
for key, val in self.__data.pairs:
|
||||
slog(prio, "{}=\"{}\"".format(key, val), caller = caller)
|
||||
|
||||
def keys(self):
|
||||
def keys(self) -> Any:
|
||||
return self.__dict.keys()
|
||||
|
||||
def items(self):
|
||||
def items(self) -> Any:
|
||||
#return self.__dict.items()
|
||||
return self.__data.pairs
|
||||
|
||||
def get(self, key, default = None, by_index = False):
|
||||
def get(self, key: Any, default: Any = None, by_index: bool = False) -> Any:
|
||||
if by_index:
|
||||
if isinstance(key, int):
|
||||
raise KeyError(
|
||||
'Tried to get value from options string with ' +
|
||||
'index {} of type "{}": {}'.format(key, type(key), str(self))
|
||||
)
|
||||
if key >= len(self.__data.pairs):
|
||||
if isinstance(key, int) and key >= len(self.__data.pairs):
|
||||
if default is not None:
|
||||
return default
|
||||
raise KeyError(
|
||||
'Tried to get value from options string with ' +
|
||||
'index {} of {}: {}'.format(key, len(self.__data.pairs), str(self))
|
||||
)
|
||||
return self.__list[key]
|
||||
if isinstance(key, int):
|
||||
return self.__list[key]
|
||||
if key in self.__dict.keys():
|
||||
return self.__dict[key]
|
||||
if default is not None:
|
||||
|
|
@ -168,7 +175,7 @@ class Options: # export
|
|||
'Key "{}" is not present in options string: {}'.format(key, str(self))
|
||||
)
|
||||
|
||||
def update(self, rhs):
|
||||
def update(self, rhs: Any) -> None:
|
||||
if hasattr(rhs, 'items'):
|
||||
for key, val in rhs.items():
|
||||
self.__dict[key] = val
|
||||
|
|
@ -182,6 +189,6 @@ class Options: # export
|
|||
)
|
||||
)
|
||||
|
||||
def append_to(self, obj):
|
||||
def append_to(self, obj: Any) -> None:
|
||||
for opt in self.__list:
|
||||
setattr(obj, opt[0], opt[1])
|
||||
|
|
|
|||
Loading…
Reference in a new issue