diff --git a/make/project.conf b/make/project.conf index 2540d86..4a29172 100644 --- a/make/project.conf +++ b/make/project.conf @@ -14,7 +14,7 @@ jw-maintainer = jan libname = none [pkg.requires.os] -run = python3-magic, python3-termcolor +run = python3-magic, python3-termcolor mypy [pkg.requires.jw] devel = jw-python-run = VERSION-REVISION, jw-build-devel = VERSION diff --git a/tools/python/Makefile b/tools/python/Makefile index b1ec41b..de51571 100644 --- a/tools/python/Makefile +++ b/tools/python/Makefile @@ -1,4 +1,4 @@ TOPDIR = ../.. include $(TOPDIR)/make/proj.mk -include $(JWBDIR)/make/dirs.mk +include $(JWBDIR)/make/py-mods.mk diff --git a/tools/python/jwutils/Cmd.py b/tools/python/jwutils/Cmd.py index 329cc5a..90e78b7 100644 --- a/tools/python/jwutils/Cmd.py +++ b/tools/python/jwutils/Cmd.py @@ -1,11 +1,9 @@ import abc import argparse +from abc import ABC from jwutils import log -# compatible with Python 2 *and* 3 -ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()}) - # full blown example of one level of nested subcommands # git -C project remote -v show -n myremote diff --git a/tools/python/jwutils/Object.py b/tools/python/jwutils/Object.py index 78e3b3c..8b47386 100644 --- a/tools/python/jwutils/Object.py +++ b/tools/python/jwutils/Object.py @@ -3,7 +3,7 @@ import jwutils.log class Object(object): # export - def __init__(): + def __init__(self): self.log_level = jwutils.log.level def log(self, prio, *args): diff --git a/tools/python/jwutils/Process.py b/tools/python/jwutils/Process.py index faf0084..e1cba91 100644 --- a/tools/python/jwutils/Process.py +++ b/tools/python/jwutils/Process.py @@ -1,5 +1,7 @@ +from __future__ import annotations from abc import ABC, abstractmethod from enum import Enum, Flag, auto +from typing import * def _sigchld_handler(signum, process): if not signum == signal.SIGCHLD: @@ -8,7 +10,7 @@ def _sigchld_handler(signum, process): class Process(ABC): # export - __processes = [] + __processes: List[Process] = [] class State(Enum): Running = auto() diff --git a/tools/python/jwutils/Signals.py b/tools/python/jwutils/Signals.py index 52d7819..af178e8 100644 --- a/tools/python/jwutils/Signals.py +++ b/tools/python/jwutils/Signals.py @@ -1,6 +1,7 @@ from abc import ABC, abstractmethod +from typing import Dict, Callable -_handled_signals = {} +_handled_signals: Dict[int, Callable] = {} def _signal_handler(signal, frame): if not signal in _handled_signals.keys(): diff --git a/tools/python/jwutils/algo/ShuntingYard.py b/tools/python/jwutils/algo/ShuntingYard.py index 7368e9b..a1e0970 100644 --- a/tools/python/jwutils/algo/ShuntingYard.py +++ b/tools/python/jwutils/algo/ShuntingYard.py @@ -255,7 +255,7 @@ if __name__ == '__main__': # ------------- testbed calculator - from string import atof + from locale import atof class Calculator(ShuntingYard): @@ -288,7 +288,7 @@ if __name__ == '__main__': super(Calculator, self).__init__(operators) rr = Calculator().eval("( 2 * 3 + 4 * 5 ) / ( 5 - 3 )") - self.debug("Result =", rr) + print("Result =", rr) # ------------- testbed match object @@ -335,4 +335,4 @@ if __name__ == '__main__': obj = Object("hans", "wurst") r = Matcher(obj).eval("name=hans and (not label~=worst)") - self.debug("Result =", r) + print("Result =", r) diff --git a/tools/python/jwutils/misc.py b/tools/python/jwutils/misc.py index a3ef204..2f0486f 100644 --- a/tools/python/jwutils/misc.py +++ b/tools/python/jwutils/misc.py @@ -3,8 +3,9 @@ import atexit import tempfile import inspect from jwutils import log +from typing import Set -_tmpfiles = set() +_tmpfiles: Set[str] = set() def _cleanup(): for f in _tmpfiles: diff --git a/tools/python/jwutils/stree/StringTree.py b/tools/python/jwutils/stree/StringTree.py index bbf4e79..b183ed8 100644 --- a/tools/python/jwutils/stree/StringTree.py +++ b/tools/python/jwutils/stree/StringTree.py @@ -55,7 +55,7 @@ class StringTree: # export self.content = rhs.content for name, c in rhs.children.items(): if not name in self.children.keys(): - slog(DEBUG, "{}: adding new child: ".format(str(self), str(c))) + slog(DEBUG, "{}: adding new child: {}".format(str(self), str(c))) self.children[name] = c else: self.children[name].__add_children(c)