jw-python/src/python/jw/util/db/query/Query.py
Jan Lindemann 9323529187
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>
2026-08-12 23:10:13 +00:00

59 lines
1.5 KiB
Python

from __future__ import annotations
import abc
from typing import TYPE_CHECKING, Any, cast
if TYPE_CHECKING:
from ..DataBase import DataBase
from ..Session import Session
from .Queries import Queries
from .QueryResult import QueryResult
class Query(abc.ABC): # export
def __init__(self, parent: Any) -> None:
self.__parent = parent
# -- pure virtuals
@abc.abstractmethod
def _run(self, session: Session, *args: Any, **kwargs: Any) -> QueryResult:
raise Exception('Called pure virtual _run()')
@abc.abstractmethod
def _register(self) -> None:
raise Exception('Called pure virtual _register()')
@abc.abstractmethod
def _column_names(self) -> list[str]:
raise Exception('Called pure virtual _column()')
# -- used by Queries class
def register(self) -> None:
return self._register()
# -- to be used
def _add(self, query_name: str, location: str, func: Any) -> None:
self.__parent.add(self, query_name, location, func)
def run(self, session: Session, *args: Any, **kwargs: Any) -> QueryResult:
return self._run(session, *args, **kwargs)
@property
def parent(self) -> Queries:
return cast('Queries', self.__parent)
@property
def db(self) -> DataBase:
return cast('DataBase', self.__parent.db)
@property
def schema(self) -> Any:
return self.__parent.db.schema
@property
def column_names(self) -> list[str]:
return self._column_names()