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
30 changed files with 247 additions and 220 deletions
|
|
@ -29,7 +29,7 @@ class ArgsContainer: # export
|
|||
self.__values[name] = value
|
||||
self.__specified_args.append(name)
|
||||
|
||||
def add_argument(self, *args, **kwargs):
|
||||
def add_argument(self, *args: Any, **kwargs: Any) -> None:
|
||||
for arg in args:
|
||||
if arg[0] != '-':
|
||||
name = arg
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from typing import Any
|
|||
|
||||
class Bunch: # export
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
def __getitem__(self, key: str) -> Any:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
from typing import Any
|
||||
|
||||
class CppState: # export
|
||||
|
||||
def __init__(self):
|
||||
__pair_square: list[str]
|
||||
__pair_curly: list[str]
|
||||
__pair_ext: list[str]
|
||||
__pair_paren: list[str]
|
||||
__pair_c_comment: list[str]
|
||||
__pair_special: list[str]
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__pair_square = ['[', ']']
|
||||
self.__pair_curly = ['{', '}']
|
||||
self.__pair_ext = ['<', '>']
|
||||
|
|
@ -9,7 +18,7 @@ class CppState: # export
|
|||
self.__pair_special = ['?', '?']
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
self.curly = 0
|
||||
self.square = 0
|
||||
self.ext = 0
|
||||
|
|
@ -17,14 +26,14 @@ class CppState: # export
|
|||
self.in_c_comment = False
|
||||
self.in_cpp_comment = False
|
||||
self.in_special = False
|
||||
self.rule = []
|
||||
self.rules = []
|
||||
self.things = []
|
||||
self.rule: list[str] = []
|
||||
self.rules: list[str] = []
|
||||
self.things: list[list[str]] = []
|
||||
|
||||
def optional(self):
|
||||
def optional(self) -> bool:
|
||||
return self.square != 0 or self.curly != 0
|
||||
|
||||
def update(self, tok, line):
|
||||
def update(self, tok: str, line: Any) -> bool | None:
|
||||
if not self.in_comment():
|
||||
if tok == '[':
|
||||
self.square += 1
|
||||
|
|
@ -68,7 +77,7 @@ class CppState: # export
|
|||
if self.in_cpp_comment:
|
||||
if tok == '\n':
|
||||
self.in_cpp_comment = False
|
||||
return
|
||||
return None
|
||||
if tok == '/*':
|
||||
raise Exception("Nested C-style comment", tok, "in line", line)
|
||||
elif tok == '*/':
|
||||
|
|
@ -79,25 +88,25 @@ class CppState: # export
|
|||
raise Exception("Unbalanced BNF bracket", tok, "in line", line)
|
||||
return self.optional()
|
||||
|
||||
def in_list(self):
|
||||
def in_list(self) -> bool:
|
||||
return self.curly > 0
|
||||
|
||||
def in_option(self):
|
||||
def in_option(self) -> bool:
|
||||
return self.square > 0
|
||||
|
||||
def in_paren(self):
|
||||
def in_paren(self) -> bool:
|
||||
return self.paren > 0
|
||||
|
||||
def in_ext(self):
|
||||
def in_ext(self) -> bool:
|
||||
return self.ext > 0
|
||||
|
||||
def in_comment(self):
|
||||
def in_comment(self) -> bool:
|
||||
return self.in_c_comment or self.in_cpp_comment
|
||||
|
||||
def in_something(self):
|
||||
def in_something(self) -> list[str] | None:
|
||||
if len(self.things) == 0:
|
||||
return None
|
||||
return self.things[-1]
|
||||
|
||||
def is_optional(self):
|
||||
def is_optional(self) -> bool:
|
||||
return self.in_list() or self.in_option()
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class Object(abc.ABC):
|
|||
def log_name(self) -> str:
|
||||
return self._log_name()
|
||||
|
||||
def log(self, prio, *args):
|
||||
def log(self, prio: int, *args: Any) -> None:
|
||||
if self.log_level == log.log_level():
|
||||
log.slog(prio, args)
|
||||
return
|
||||
|
|
@ -65,5 +65,5 @@ class Object(abc.ABC):
|
|||
if len(msg):
|
||||
print(msg[1:])
|
||||
|
||||
def debug(self, *args):
|
||||
def debug(self, *args: Any) -> None:
|
||||
log.slog(log.DEBUG, args)
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ import signal
|
|||
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import Enum, Flag, auto
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from .log import ERR, slog
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .Signals import Signals
|
||||
|
||||
def _sigchld_handler(signum, process):
|
||||
def _sigchld_handler(signum: Any, process: Process) -> None:
|
||||
if not signum == signal.SIGCHLD:
|
||||
return
|
||||
Process.propagate_signal(signum)
|
||||
|
|
@ -28,7 +28,7 @@ class Process(ABC): # export
|
|||
class Flags(Flag):
|
||||
FailOnExitWithoutShutdown = auto()
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.__state = Process.State.Running
|
||||
self.__flags = self.Flags.FailOnExitWithoutShutdown
|
||||
if len(self.__processes) == 0:
|
||||
|
|
@ -36,15 +36,15 @@ class Process(ABC): # export
|
|||
self.__processes.add(self)
|
||||
|
||||
@classmethod
|
||||
def propagate_signal(cls, signum):
|
||||
def propagate_signal(cls, signum: Any) -> None:
|
||||
cls.signals().propagate(signum)
|
||||
|
||||
def signal(self, signum):
|
||||
def signal(self, signum: Any) -> None:
|
||||
if signum == signal.SIGCHLD:
|
||||
self.exited()
|
||||
|
||||
@abstractmethod
|
||||
def _pid(self):
|
||||
def _pid(self) -> Any:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
|
|
@ -53,19 +53,19 @@ class Process(ABC): # export
|
|||
pass
|
||||
|
||||
# to be reimplemented
|
||||
def _request_shutdown(self):
|
||||
def _request_shutdown(self) -> None:
|
||||
pass
|
||||
|
||||
# to be reimplemented
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
return str(self._pid())
|
||||
|
||||
def request_shutdown(self):
|
||||
def request_shutdown(self) -> None:
|
||||
if not self.__state == Process.State.Shutdown:
|
||||
self.__state = Process.State.Shutdown
|
||||
self._request_shutdown()
|
||||
|
||||
def exited(self):
|
||||
def exited(self) -> None:
|
||||
if self.__state == Process.State.Running:
|
||||
slog(ERR, 'process exited unexpectedly')
|
||||
if self.__flags & Process.Flags.FailOnExitWithoutShutdown:
|
||||
|
|
|
|||
|
|
@ -4,17 +4,18 @@ import os
|
|||
import io
|
||||
import sys
|
||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||
from typing import Any
|
||||
|
||||
class RedirectStdIO: # export
|
||||
|
||||
def __init__(self, stderr = 'on', stdout = 'off'):
|
||||
def __init__(self, stderr: str = 'on', stdout: str = 'off') -> None:
|
||||
self.__stderr = stderr
|
||||
self.__stdout = stdout
|
||||
# TODO: arguments not fully implemented,
|
||||
# Add support for 'off', 'on', 'stdxxx' (redirection)
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
def __enter__(self) -> 'RedirectStdIO':
|
||||
if self.__stdout == 'off':
|
||||
rfd, wfd = os.pipe()
|
||||
flags = fcntl(rfd, F_GETFL)
|
||||
|
|
@ -24,8 +25,9 @@ class RedirectStdIO: # export
|
|||
self.real_stdout_fd = os.dup(1)
|
||||
#os.close(1)
|
||||
os.dup2(wfd, 1)
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
def __exit__(self, type: Any, value: Any, traceback: Any) -> None:
|
||||
if self.__stdout == 'off':
|
||||
sys.stdout.flush()
|
||||
os.dup2(self.real_stdout_fd, 1)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,28 @@
|
|||
from abc import abstractmethod
|
||||
from typing import Dict
|
||||
from typing import Any, Callable, Dict, List, Union
|
||||
|
||||
class Signals:
|
||||
|
||||
class Handler:
|
||||
|
||||
def __init__(self, func, args):
|
||||
def __init__(self, func: Callable[..., Any], args: tuple[Any, ...]) -> None:
|
||||
self.func = func
|
||||
self.args = args
|
||||
|
||||
def __init(self):
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def _add_handler(cls, signal, handler):
|
||||
def _add_handler(cls, signal: int, handler: Callable[..., Any]) -> None:
|
||||
raise Exception("_add_handler() is not reimplemented")
|
||||
|
||||
@classmethod
|
||||
def add_handler(cls, signals, handler, *args):
|
||||
def add_handler(
|
||||
cls, signals: Union[int, List[int]], handler: Callable[..., Any], *args: Any
|
||||
) -> None:
|
||||
if isinstance(signals, int):
|
||||
signals = [signals]
|
||||
for signal in signals:
|
||||
h = Signals.Handler(handler, args)
|
||||
if signal not in _handled_signals.keys():
|
||||
|
|
@ -28,12 +32,12 @@ class Signals:
|
|||
_handled_signals[signal].append(h)
|
||||
|
||||
@classmethod
|
||||
def propagate(cls, signal):
|
||||
def propagate(cls, signal: int) -> None:
|
||||
_signal_handler(signal, None)
|
||||
|
||||
_handled_signals: Dict[int, list[Signals.Handler]] = {}
|
||||
|
||||
def _signal_handler(signal, frame):
|
||||
def _signal_handler(signal: int, frame: Any) -> None:
|
||||
if signal not in _handled_signals.keys():
|
||||
return
|
||||
for h in _handled_signals[signal]:
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from .log import get_caller_pos, slog
|
||||
|
||||
class StopWatch: # export
|
||||
|
||||
def __init__(self, name = ''):
|
||||
def __init__(self, name: str = '') -> None:
|
||||
self.__start = datetime.now()
|
||||
self.__last = self.__start
|
||||
self.name = name
|
||||
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
self.__start = datetime.now()
|
||||
|
||||
def logDelta(self, prio, *args, **kwargs):
|
||||
def logDelta(self, prio: int, *args: Any, **kwargs: Any) -> None:
|
||||
now = datetime.now()
|
||||
if args is not None:
|
||||
if args:
|
||||
msg = ' '.join(args)
|
||||
else:
|
||||
msg = '------------------ '
|
||||
|
|
|
|||
|
|
@ -20,19 +20,19 @@ class Operator: # export
|
|||
|
||||
class Stack:
|
||||
|
||||
def __init__(self, itemlist: list[Any] = []):
|
||||
def __init__(self, itemlist: list[Any] = []) -> None:
|
||||
self.items = itemlist
|
||||
|
||||
@override
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return str(self.items)
|
||||
|
||||
def isEmpty(self):
|
||||
def isEmpty(self) -> bool:
|
||||
if self.items == []:
|
||||
return True
|
||||
return False
|
||||
|
||||
def peek(self):
|
||||
def peek(self) -> Any:
|
||||
return self.items[-1:][0]
|
||||
|
||||
def pop(self) -> Any:
|
||||
|
|
@ -62,7 +62,7 @@ class ShuntingYard(object): # export
|
|||
def operator(self, key: str) -> Operator:
|
||||
return self.__ops[key]
|
||||
|
||||
def token_string(self):
|
||||
def token_string(self) -> str:
|
||||
r = ""
|
||||
for k in sorted(self.__ops):
|
||||
v = self.__ops[k]
|
||||
|
|
@ -79,7 +79,6 @@ class ShuntingYard(object): # export
|
|||
return r
|
||||
|
||||
def tokenize(self, spec: str) -> list[tuple[str, Any]]:
|
||||
|
||||
regex = ""
|
||||
for k in self.__ops.keys():
|
||||
regex = regex + "|" + re.escape(k)
|
||||
|
|
@ -194,7 +193,7 @@ class ShuntingYard(object): # export
|
|||
)
|
||||
return cast('list[str]', table[-1][2])
|
||||
|
||||
def infix_to_postfix_orig(self, infix):
|
||||
def infix_to_postfix_orig(self, infix: str) -> list[str]:
|
||||
|
||||
s = Stack()
|
||||
r = []
|
||||
|
|
@ -285,16 +284,16 @@ if __name__ == '__main__':
|
|||
#def tokenize(self, string):
|
||||
# return string.split()
|
||||
|
||||
def f_mult(self, a, b):
|
||||
def f_mult(self, a: str, b: str) -> str:
|
||||
return str(atof(a) * atof(b))
|
||||
|
||||
def f_div(self, a, b):
|
||||
def f_div(self, a: str, b: str) -> str:
|
||||
return str(atof(a) / atof(b))
|
||||
|
||||
def f_add(self, a, b):
|
||||
def f_add(self, a: str, b: str) -> str:
|
||||
return str(atof(a) + atof(b))
|
||||
|
||||
def f_sub(self, a, b):
|
||||
def f_sub(self, a: str, b: str) -> str:
|
||||
return str(atof(a) - atof(b))
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
|
@ -319,22 +318,22 @@ if __name__ == '__main__':
|
|||
|
||||
class Matcher(ShuntingYard):
|
||||
|
||||
def f_is_name(self, a):
|
||||
def f_is_name(self, a: str) -> str:
|
||||
if obj.Name == a:
|
||||
return "True"
|
||||
return "False"
|
||||
|
||||
def f_matches_label(self, a):
|
||||
def f_matches_label(self, a: str) -> str:
|
||||
if re.match(a, obj.Label):
|
||||
return "True"
|
||||
return "False"
|
||||
|
||||
def f_is_not(self, a):
|
||||
def f_is_not(self, a: str) -> str:
|
||||
if a == "True":
|
||||
return "False"
|
||||
return "True"
|
||||
|
||||
def f_and(self, a_, b_):
|
||||
def f_and(self, a_: str, b_: str) -> str:
|
||||
a = a_ == "True"
|
||||
b = b_ == "True"
|
||||
if a and b:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from abc import abstractmethod
|
||||
from typing import override
|
||||
from typing import Any, override
|
||||
|
||||
from ..Process import Process as ProcessBase
|
||||
from .Signals import Signals
|
||||
|
|
@ -8,15 +8,15 @@ class Process(ProcessBase): # export
|
|||
|
||||
__signals = Signals()
|
||||
|
||||
def __init__(self, aio):
|
||||
def __init__(self, aio: Any) -> None:
|
||||
super().__init__()
|
||||
self.aio = aio
|
||||
|
||||
@override
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def signals(cls):
|
||||
def signals(cls) -> Signals:
|
||||
return cls.__signals
|
||||
|
||||
def wait(self):
|
||||
def wait(self) -> Any:
|
||||
return self.aio.wait()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class ShellCmd: # export
|
|||
super().__init__()
|
||||
|
||||
@override
|
||||
def pipe_data_received(self, fd, data):
|
||||
def pipe_data_received(self, fd: Any, data: Any) -> None:
|
||||
stream = "stdout" if fd == 1 else ("stderr" if fd == 2 else str(fd))
|
||||
tag = stream + '@' + self.name
|
||||
data = data.decode().rstrip('\n')
|
||||
|
|
@ -25,7 +25,7 @@ class ShellCmd: # export
|
|||
slog(prio, "[%s] %s" % (tag, line.rstrip('\r\n')))
|
||||
|
||||
@override
|
||||
def process_exited(self):
|
||||
def process_exited(self) -> None:
|
||||
slog(DEBUG, "[%s] process exited" % (self.name))
|
||||
super().process_exited()
|
||||
self.process.exited()
|
||||
|
|
@ -88,7 +88,7 @@ class ShellCmd: # export
|
|||
return self.__rc
|
||||
|
||||
# to be called from SubprocessProtocol / SIGCHLD handler
|
||||
def exited(self):
|
||||
def exited(self) -> None:
|
||||
slog(DEBUG, "Process {} exited".format(self.__name))
|
||||
self.__reap()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import asyncio
|
||||
|
||||
from typing import override
|
||||
from typing import Any, override
|
||||
|
||||
from ..Signals import Signals as SignalsBase
|
||||
|
||||
|
|
@ -9,6 +9,6 @@ class Signals(SignalsBase):
|
|||
# reimplemented from Signals
|
||||
@override
|
||||
@classmethod
|
||||
def _add_handler(cls, signal, handler):
|
||||
def _add_handler(cls, signal: Any, handler: Any) -> None:
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.add_signal_handler(signal, handler, None) # None = *args
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Entity(EntityBase): # export
|
|||
self.__email: str = conf['email']
|
||||
|
||||
@property
|
||||
def conf(self):
|
||||
def conf(self) -> Config:
|
||||
return self.__conf
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
import abc
|
||||
|
||||
from contextlib import contextmanager
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Generator
|
||||
|
||||
from ..log import NOTICE
|
||||
|
||||
|
|
@ -27,15 +27,15 @@ class DataBase(abc.ABC):
|
|||
del session
|
||||
|
||||
@property
|
||||
def schema(self):
|
||||
def schema(self) -> Schema:
|
||||
return self.__schema
|
||||
|
||||
@property
|
||||
def conf(self):
|
||||
def conf(self) -> Config:
|
||||
return self.__conf
|
||||
|
||||
@contextmanager
|
||||
def session(self):
|
||||
def session(self) -> Generator[Session, None, None]:
|
||||
ret = self._create_session()
|
||||
try:
|
||||
yield ret
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import abc
|
||||
from typing import Any
|
||||
|
||||
class Session(abc.ABC): # export
|
||||
|
||||
def __init__(self, db):
|
||||
def __init__(self, db: Any) -> None:
|
||||
self.__db = db
|
||||
|
||||
@property
|
||||
def db(self):
|
||||
def db(self) -> Any:
|
||||
return self.__db
|
||||
|
|
|
|||
|
|
@ -1,41 +1,43 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Union, cast
|
||||
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union, cast
|
||||
|
||||
from ..log import ERR, INFO, OFF, slog, slog_m
|
||||
from .rows import rows_check_not_null, rows_dump, rows_duplicates
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .schema.Schema import Schema
|
||||
from .schema.Table import Table
|
||||
|
||||
TType = Union[Any, Dict[str, Any]]
|
||||
|
||||
class TableIoHandler(ABC): # export
|
||||
|
||||
def __init__(self, schema: Schema):
|
||||
self.__table_meta = None
|
||||
def __init__(self, schema: Schema) -> None:
|
||||
self.__table_meta: Optional[Table] = None
|
||||
self.__schema = schema
|
||||
|
||||
@property
|
||||
def _table_meta(self):
|
||||
def _table_meta(self) -> Table:
|
||||
if self.__table_meta is None:
|
||||
self.__table_meta = self.__schema.table_by_model_name(
|
||||
self.__class__.__name__, throw = True
|
||||
)
|
||||
assert self.__table_meta is not None
|
||||
return self.__table_meta
|
||||
|
||||
@property
|
||||
def _table_name(self):
|
||||
def _table_name(self) -> str:
|
||||
return self._table_meta.name
|
||||
|
||||
@property
|
||||
def _primary_keys(self):
|
||||
def _primary_keys(self) -> Any:
|
||||
return self._table_meta.primary_keys
|
||||
|
||||
def _check_non_nullable(self, rows: list[dict[str, Any]]) -> None:
|
||||
buf: list[dict[str, Any]] = []
|
||||
non_nullable = self._table_meta.not_null_insertible_columns
|
||||
non_nullable: list[str] = list(self._table_meta.not_null_insertible_columns)
|
||||
try:
|
||||
rows_check_not_null(rows, list(non_nullable), buf = buf)
|
||||
except:
|
||||
|
|
@ -61,7 +63,7 @@ class TableIoHandler(ABC): # export
|
|||
raise
|
||||
|
||||
@property
|
||||
def log_columns(self):
|
||||
def log_columns(self) -> Iterable[str]:
|
||||
return self._table_meta.log_columns
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class Queries(abc.ABC): # export
|
|||
|
||||
@property
|
||||
def schema(self) -> Schema:
|
||||
return cast('Schema', self.__db.schema)
|
||||
return self.__db.schema
|
||||
|
||||
def add(self, query: QueryBase, query_name: str, location: str, func: Any) -> None:
|
||||
slog(INFO, f'Adding query "{query_name}" on location "{location}"')
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Query(abc.ABC): # export
|
|||
return cast('DataBase', self.__parent.db)
|
||||
|
||||
@property
|
||||
def schema(self):
|
||||
def schema(self) -> Any:
|
||||
return self.__parent.db.schema
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class QueryResult(abc.ABC): # export
|
|||
return cast('DataBase', self.__query.db)
|
||||
|
||||
@property
|
||||
def query(self) -> DataBase:
|
||||
def query(self) -> Any:
|
||||
return cast('DataBase', self.__query)
|
||||
|
||||
@property
|
||||
|
|
@ -35,7 +35,7 @@ class QueryResult(abc.ABC): # export
|
|||
return self.__session
|
||||
|
||||
@property
|
||||
def schema(self):
|
||||
def schema(self) -> Any:
|
||||
return self.__query.db.schema
|
||||
|
||||
def rows(self) -> list[Any]:
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue