mypy: Fix disallow_untyped_calls check fallout
Add return type annotations and parameter type hints to previously untyped functions, preparing for disallow_untyped_calls enforcement: - ArgsContainer.py: keys() -> Iterable[str] - Object.py: Object.__init__() -> None - ShuntingYard.py: tokenize(), infix_to_postfix(), __init__(), add_operator(), Stack methods, debug(), Calculator/Matcher.__init__() - ShellCmd.py: __exec(), __cleanup(), init(), cleanup(), __init__() - Auth.py: __bind() -> Connection, import Connection - TableIoHandler.py: _check_non_nullable() -> None, buf annotation - Queries.py: _add() -> None - rows.py: __equal(), rows_duplicates(), rows_check_not_null(), rows_dump(), rows_dumps() with proper type signatures - CompositeForeignKey.py: __table() -> Table - EventRouter.py: iter_peers() -> Iterator[tuple[str, Any]] - MapAttr2Shape.py: __value(), __add_key_nodegraphics() - ldap.py: __search() -> str, collect() -> set[str] - multi_key_dict.py: has_key(), get_other_keys(), iterkeys(), get_values_from_str(), test_multi_key_dict(), __init__(), items_dict annotation 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
ec342ba172
commit
e014a9251f
1 changed files with 76 additions and 66 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import re
|
||||
from typing import cast, override
|
||||
from typing import Any, cast, override
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ ARG, KEYW, QUOTED, LPAREN, RPAREN = 'arg kw quoted ( )'.split()
|
|||
|
||||
class Operator: # export
|
||||
|
||||
def __init__(self, func = None, nargs = 2, precedence = 3, assoc = L):
|
||||
def __init__(self, func = None, nargs: int = 2, precedence: int = 3, assoc = L):
|
||||
self.func = func
|
||||
self.nargs = nargs
|
||||
self.prec = precedence
|
||||
|
|
@ -18,7 +18,7 @@ class Operator: # export
|
|||
|
||||
class Stack:
|
||||
|
||||
def __init__(self, itemlist = []):
|
||||
def __init__(self, itemlist: list[Any] = []):
|
||||
self.items = itemlist
|
||||
|
||||
@override
|
||||
|
|
@ -33,23 +33,23 @@ class Stack:
|
|||
def peek(self):
|
||||
return self.items[-1:][0]
|
||||
|
||||
def pop(self):
|
||||
def pop(self) -> Any:
|
||||
return self.items.pop()
|
||||
|
||||
def push(self, item):
|
||||
def push(self, item: Any) -> int:
|
||||
self.items.append(item)
|
||||
return 0
|
||||
|
||||
class ShuntingYard(object): # export
|
||||
|
||||
def __init__(self, operators = None):
|
||||
def __init__(self, operators: dict[str, Any] | None = None):
|
||||
self.do_debug = prio_gets_logged(DEBUG)
|
||||
self.__ops = {}
|
||||
self.__ops: dict[str, Operator] = {}
|
||||
if operators is not None:
|
||||
for k, v in operators.items():
|
||||
self.add_operator(k, v.func, v.nargs, v.prec, v.assoc)
|
||||
|
||||
def debug(self, *args):
|
||||
def debug(self, *args: Any) -> None:
|
||||
if self.do_debug:
|
||||
msg = ""
|
||||
for count, thing in enumerate(args):
|
||||
|
|
@ -58,7 +58,7 @@ class ShuntingYard(object): # export
|
|||
slog(DEBUG, msg[1:], caller = get_caller_pos())
|
||||
|
||||
def operator(self, key: str) -> Operator:
|
||||
return cast('Operator', self.__ops[key])
|
||||
return self.__ops[key]
|
||||
|
||||
def token_string(self):
|
||||
r = ""
|
||||
|
|
@ -76,7 +76,7 @@ class ShuntingYard(object): # export
|
|||
return r[2:]
|
||||
return r
|
||||
|
||||
def tokenize(self, spec):
|
||||
def tokenize(self, spec) -> list[tuple[str, Any]]:
|
||||
|
||||
regex = ""
|
||||
for k in self.__ops.keys():
|
||||
|
|
@ -84,7 +84,7 @@ class ShuntingYard(object): # export
|
|||
|
||||
regex = regex[1:]
|
||||
|
||||
scanner = re.Scanner( # pyright: ignore[reportAttributeAccessIssue]
|
||||
scanner = re.Scanner( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
|
||||
[
|
||||
(regex, lambda scanner, token: (KEYW, token)),
|
||||
(r"\"[^\"]*\"|'[^']*'", lambda scanner, token: (QUOTED, token[1:-1])),
|
||||
|
|
@ -100,7 +100,7 @@ class ShuntingYard(object): # export
|
|||
)
|
||||
|
||||
#self.debug(tokens)
|
||||
return tokens
|
||||
return cast(list[tuple[str, Any]], tokens)
|
||||
r = []
|
||||
for e in tokens:
|
||||
if e[0] == "quoted":
|
||||
|
|
@ -110,14 +110,15 @@ class ShuntingYard(object): # export
|
|||
|
||||
return r
|
||||
|
||||
def add_operator(self, name, func, nargs, precedence, assoc):
|
||||
def add_operator(self, name: str, func: Any, nargs: int, precedence: int, assoc: Any) -> None:
|
||||
self.__ops[name] = Operator(func, nargs, precedence, assoc)
|
||||
|
||||
def infix_to_postfix(self, infix):
|
||||
def infix_to_postfix(self, infix) -> list[str]:
|
||||
tokenized = self.tokenize(infix)
|
||||
self.debug("tokenized = ", tokenized)
|
||||
outq, stack = [], []
|
||||
table = ['TOKEN', 'ACTION', 'RPN OUTPUT', ('OP STACK', ), 'NOTES']
|
||||
outq: list[str] = []
|
||||
stack: list[Any] = []
|
||||
table: list[Any] = ['TOKEN', 'ACTION', 'RPN OUTPUT', ('OP STACK', ), 'NOTES']
|
||||
for toktype, token in tokenized:
|
||||
self.debug("Checking token", token)
|
||||
note = action = ''
|
||||
|
|
@ -195,7 +196,7 @@ class ShuntingYard(object): # export
|
|||
for (width, cell) in zip(maxcolwidths, row)
|
||||
)
|
||||
)
|
||||
return table[-1][2]
|
||||
return cast(list[str], table[-1][2])
|
||||
|
||||
def infix_to_postfix_orig(self, infix):
|
||||
|
||||
|
|
@ -242,7 +243,7 @@ class ShuntingYard(object): # export
|
|||
return r
|
||||
#return " ".join(r)
|
||||
|
||||
def eval_postfix(self, postfixexpr):
|
||||
def eval_postfix(self, postfixexpr) -> Any:
|
||||
|
||||
self.debug("postfix = ", postfixexpr)
|
||||
vals = Stack()
|
||||
|
|
@ -269,7 +270,7 @@ class ShuntingYard(object): # export
|
|||
|
||||
return vals.pop()
|
||||
|
||||
def eval(self, infix):
|
||||
def eval(self, infix) -> Any:
|
||||
if not isinstance(infix, str):
|
||||
return infix
|
||||
postfix = self.infix_to_postfix(infix)
|
||||
|
|
@ -301,7 +302,7 @@ if __name__ == '__main__':
|
|||
def f_sub(self, a, b):
|
||||
return str(atof(a) - atof(b))
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
Op = Operator
|
||||
operators = {
|
||||
'^': Op(None, 2, 4, R),
|
||||
|
|
@ -345,7 +346,7 @@ if __name__ == '__main__':
|
|||
return "True"
|
||||
return "False"
|
||||
|
||||
def __init__(self, obj):
|
||||
def __init__(self, obj) -> None:
|
||||
Op = Operator
|
||||
operators = {
|
||||
'(': Op(None, 2, 9, L),
|
||||
|
|
|
|||
Loading…
Reference in a new issue