mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
Fix Python errors reported by mypy
This commit fixes Python errors and warnings reported by static type checking with mypy. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
a9dd9c7d0d
commit
952bf4a4e1
9 changed files with 15 additions and 13 deletions
|
|
@ -14,7 +14,7 @@ jw-maintainer = jan
|
||||||
libname = none
|
libname = none
|
||||||
|
|
||||||
[pkg.requires.os]
|
[pkg.requires.os]
|
||||||
run = python3-magic, python3-termcolor
|
run = python3-magic, python3-termcolor mypy
|
||||||
|
|
||||||
[pkg.requires.jw]
|
[pkg.requires.jw]
|
||||||
devel = jw-python-run = VERSION-REVISION, jw-build-devel = VERSION
|
devel = jw-python-run = VERSION-REVISION, jw-build-devel = VERSION
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
TOPDIR = ../..
|
TOPDIR = ../..
|
||||||
|
|
||||||
include $(TOPDIR)/make/proj.mk
|
include $(TOPDIR)/make/proj.mk
|
||||||
include $(JWBDIR)/make/dirs.mk
|
include $(JWBDIR)/make/py-mods.mk
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
import abc
|
import abc
|
||||||
import argparse
|
import argparse
|
||||||
|
from abc import ABC
|
||||||
|
|
||||||
from jwutils import log
|
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
|
# full blown example of one level of nested subcommands
|
||||||
# git -C project remote -v show -n myremote
|
# git -C project remote -v show -n myremote
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import jwutils.log
|
||||||
|
|
||||||
class Object(object): # export
|
class Object(object): # export
|
||||||
|
|
||||||
def __init__():
|
def __init__(self):
|
||||||
self.log_level = jwutils.log.level
|
self.log_level = jwutils.log.level
|
||||||
|
|
||||||
def log(self, prio, *args):
|
def log(self, prio, *args):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
from __future__ import annotations
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from enum import Enum, Flag, auto
|
from enum import Enum, Flag, auto
|
||||||
|
from typing import *
|
||||||
|
|
||||||
def _sigchld_handler(signum, process):
|
def _sigchld_handler(signum, process):
|
||||||
if not signum == signal.SIGCHLD:
|
if not signum == signal.SIGCHLD:
|
||||||
|
|
@ -8,7 +10,7 @@ def _sigchld_handler(signum, process):
|
||||||
|
|
||||||
class Process(ABC): # export
|
class Process(ABC): # export
|
||||||
|
|
||||||
__processes = []
|
__processes: List[Process] = []
|
||||||
|
|
||||||
class State(Enum):
|
class State(Enum):
|
||||||
Running = auto()
|
Running = auto()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Dict, Callable
|
||||||
|
|
||||||
_handled_signals = {}
|
_handled_signals: Dict[int, Callable] = {}
|
||||||
|
|
||||||
def _signal_handler(signal, frame):
|
def _signal_handler(signal, frame):
|
||||||
if not signal in _handled_signals.keys():
|
if not signal in _handled_signals.keys():
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# ------------- testbed calculator
|
# ------------- testbed calculator
|
||||||
|
|
||||||
from string import atof
|
from locale import atof
|
||||||
|
|
||||||
class Calculator(ShuntingYard):
|
class Calculator(ShuntingYard):
|
||||||
|
|
||||||
|
|
@ -288,7 +288,7 @@ if __name__ == '__main__':
|
||||||
super(Calculator, self).__init__(operators)
|
super(Calculator, self).__init__(operators)
|
||||||
|
|
||||||
rr = Calculator().eval("( 2 * 3 + 4 * 5 ) / ( 5 - 3 )")
|
rr = Calculator().eval("( 2 * 3 + 4 * 5 ) / ( 5 - 3 )")
|
||||||
self.debug("Result =", rr)
|
print("Result =", rr)
|
||||||
|
|
||||||
# ------------- testbed match object
|
# ------------- testbed match object
|
||||||
|
|
||||||
|
|
@ -335,4 +335,4 @@ if __name__ == '__main__':
|
||||||
obj = Object("hans", "wurst")
|
obj = Object("hans", "wurst")
|
||||||
|
|
||||||
r = Matcher(obj).eval("name=hans and (not label~=worst)")
|
r = Matcher(obj).eval("name=hans and (not label~=worst)")
|
||||||
self.debug("Result =", r)
|
print("Result =", r)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ import atexit
|
||||||
import tempfile
|
import tempfile
|
||||||
import inspect
|
import inspect
|
||||||
from jwutils import log
|
from jwutils import log
|
||||||
|
from typing import Set
|
||||||
|
|
||||||
_tmpfiles = set()
|
_tmpfiles: Set[str] = set()
|
||||||
|
|
||||||
def _cleanup():
|
def _cleanup():
|
||||||
for f in _tmpfiles:
|
for f in _tmpfiles:
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class StringTree: # export
|
||||||
self.content = rhs.content
|
self.content = rhs.content
|
||||||
for name, c in rhs.children.items():
|
for name, c in rhs.children.items():
|
||||||
if not name in self.children.keys():
|
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
|
self.children[name] = c
|
||||||
else:
|
else:
|
||||||
self.children[name].__add_children(c)
|
self.children[name].__add_children(c)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue