mypy: Fix fallout of warn-unreachable, exhaustive-match

Fix fallout of mypy --warn-unreachable --error-code=exchaustive-match.

The warn_unreachable and exhaustive-match mypy directives exposed several
classes of issues: unreachable statements after exhaustive matches,
unreachable isinstance checks on already-narrowed types, dead code after
raise statements, and missing None in type unions where the code
checked for it at runtime.

Fix the following files:
- Config.py: Broaden glob_paths parameter type to accept str, matching
  the isinstance check in the function body.
- ldap.py: Remove dead code (unreachable if-block with False condition
  and unreachable continue after raise).
- DataType.py: Use case _ fallback in py_type() match for exhaustive-
  match compliance, remove redundant isinstance check and assertion
  that were unreachable given type annotations.
- Event.py: Add | None to Dest type alias where the code checks for
  None at runtime.
- EventHub.py: Add | None to peer_confs variable type annotation where
  the code checks for None at runtime.
- StringTree.py: Fix is_quoted() to accept only str (not StringTree),
  fix __set() path parameter type to str | None, remove dead code after
  exhaustive isinstance checks, remove unnecessary assert.
- auth/ldap/Auth.py: Remove unreachable continue statement after raise.

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:
Jan Lindemann 2026-07-24 18:48:09 +02:00 • committed by janware DevOps
commit 9e24a2f394
Signed by: DevOps
SSH key fingerprint: SHA256:cZiw7ExG5q3KAVm7Jse3rGITowu0VjgUgNMPbifmY8g
5 changed files with 6 additions and 28 deletions

View file

@ -22,7 +22,7 @@ class Config(Mapping): # export
def __load(
self,
search_dirs: list[str] | None,
glob_paths: list[str] | None,
glob_paths: list[str] | str | None,
refuse_mode_mask: int | None
) -> StringTree:

View file

@ -123,7 +123,6 @@ class Auth(AuthBase): # export
except Exception as e:
slog(WARNING, f'Exception {e}')
raise
continue
for dummy_user in self.__dummy.users.values():
ret[dummy_user.name] = dummy_user
self.___users = ret

View file

@ -2,8 +2,6 @@ from datetime import datetime
from enum import Enum, auto
from typing import Optional, override
from ...log import ERR, throw
class Id(Enum):
Integer = auto()
SmallInteger = auto()
@ -31,22 +29,14 @@ def py_type(type_id: Id) -> type: # export
return str
case Id.Text:
return str
case Id.DateTime:
return datetime
raise Exception(f'Unknown column type-id "{type_id}"')
case _:
raise Exception(f'Unknown column type-id "{type_id}"')
class DataType: # export
def __init__(self, type_id: Id, size: Optional[int] = None):
if not isinstance(type_id, Id):
throw(
ERR,
f'Passed type id "{type_id}" with unsupported data type {type(type_id)}'
)
if size is not None:
assert (isinstance(size, int))
assert (size > 0)
assert size > 0
self.__id = type_id
self.__size = size

View file

@ -211,8 +211,6 @@ class Connection: # export
key: [val.decode() for val in vals]
for key, vals in entry[1].items()
}
if unroll and False:
entry = entry[0], {key: val[0] for key, val in entry[1].items()}
try:
callback(self, entry, context)
except Exception as e:

View file

@ -19,8 +19,6 @@ if TYPE_CHECKING:
from ..log import DEBUG, INFO, get_caller_pos, slog
def is_quoted(s: str) -> bool:
if isinstance(s, StringTree):
return False
s = s.strip()
if len(s) < 2:
return False
@ -85,7 +83,7 @@ class StringTree(MutableMapping): # export
def __set(
self,
path: str,
path: str | None,
content: str | StringTree | None,
split: bool = True
) -> StringTree:
@ -99,7 +97,7 @@ class StringTree(MutableMapping): # export
# works fine without.
#assert self.content != str(content)
if content is not None and type(content) not in [str, StringTree]:
if content is not None and not isinstance(content, (str, StringTree)):
raise self.Error(
"Tried to add content of unsupported type {}".format(
type(content).__name__
@ -110,12 +108,6 @@ class StringTree(MutableMapping): # export
self.content = cleanup_string(content)
elif isinstance(content, StringTree):
self.__adopt_children(content)
else:
raise self.Error(
"Tried to add content of unsupported type {}".format(
type(content).__name__
)
)
slog(
DEBUG,
" -- content = >" + str(content) + "<, self.content = >" +
@ -346,7 +338,6 @@ class StringTree(MutableMapping): # export
@override
def get(self, path: str, default: Any = None) -> StringTree | None:
slog(DEBUG, 'looking for "{}" in "{}"'.format(path, self.content))
assert not isinstance(path, int)
_path: str = cleanup_string(path)
if len(_path) == 0:
slog(DEBUG, "returning myself")