Commit graph

422 commits

Author SHA1 Message Date
3d1509419e
obj.Object: Add _name()
Object's .name property is not backed by an overridable _name() method,
fix that. Default to the name assembled from the _name_parts() method,
much like it was before, only without braces.

.log_name is for logging, and using the _name_parts() assembly is good
for that, but .name is potentially meant to be machine readable. To be
used and decided by deriving classes.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-24 18:15:47 +02:00
c810655556
obj.ConfiguredNode: Add class
Add methods for retrieving configuration values to TreeNode. The main
benefit being that config values are looked up recursively from leaf to
root.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-22 11:17:59 +02:00
fb41e6e310
obj.TreeNode: Add class
Enrich the Object class with property parent, which allows it to
participate in an object tree hierarchy.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-22 11:17:59 +02:00
9a5bff9de2
Object: Move into obj.Object
The Object is going to get narrowed variants, so move it into a
submodule of its own. Keep jw.util.Object as a compatibility shim for
now.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-22 11:17:28 +02:00
76fa902dab
Release 1.0.0-52@suse-tumbleweed/x86_64 2026-08-20 23:36:51 +00:00
0b1255797a
Release 1.0.0-52@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-08-20 23:13:45 +00:00
469b848725
Start version: 1.0.0-52
Signed-off-by: janware DevOps <devops@janware.com>
2026-08-20 23:12:54 +00:00
f7940c252f
Object.__init__(): Accept and forward kwargs
Object.__init__() takes no arguments and does not call
super().__init__(), so it is a dead end for cooperative __init__ chains.
Make __init__() accept **kwargs and forward them to super().__init__()
to fix that.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-20 08:42:21 +02:00
9d0a3f8857
load_yaml: Reorder functions from leaves to trunk
Reorder functions so that call-graph leaves appear first and the
trunk (top-level entry points) appear last:

  _deep_merge                  — leaf, no internal calls
  _parse_link                  — leaf
  _resolve_path                — leaf
  _parse_include_spec          — leaf
  _normalize_include_specs     — calls _parse_include_spec
  _merge_at_path               — calls _deep_merge
  _expand_links_recursive      — calls _parse_link, _resolve_path
  _expand_links                — calls _expand_links_recursive
  _load_yaml                   — calls _normalize_include_specs,
                                   _merge_at_path
  load_yaml                    — trunk, calls _load_yaml, _expand_links

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-20 08:41:55 +02:00
b18b2f0b65
load_yaml: Fix jw.include overriding local content
When jw.include merges content at a target path, the local content in
the main document should take precedence over the included content
(siblings win, and the main file is the ultimate source of truth).

Fix _merge_at_path so that root's existing content at the target path
wins over the value being merged in.

Also update the test_include_override_existing test to reflect the
correct semantics: local content overrides included content.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-20 08:39:54 +02:00
c514ae9077
Release 1.0.0-51@suse-tumbleweed/x86_64 2026-08-12 23:32:18 +00:00
bd6f63398d
Release 1.0.0-51@kali-rolling/amd64
Signed-off-by: janware DevOps <devops@janware.com>
2026-08-12 23:11:06 +00:00
db8cca0732
Start version: 1.0.0-51
Signed-off-by: janware DevOps <devops@janware.com>
2026-08-12 23:10:15 +00:00
2d847b4ccd
jw.util, jwutils: Follow jw-pkg's move to isort
"make format", as defined by jw-pkg, now sorts the order or imports,
too. So do that and commit.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:13 +00:00
4cf319aefd
stree.(add|clear)_hide_log_patterns(): Add functions
Add two functions, add_hide_log_patterns() and
clear_hide_log_patterns(). Their intended purpose is to keep secrets
from leaking into logging. add_hide_log_patterns() takes compiled
regular expressions, strings or arrays thereof that are added to the
global pattern list. It defaults to ["secret", "password", "token"],
case-insensitive. clear_hide_log_patterns() clears the list, so the
caller must start from scratch building one.

This keeps sensitive keys visible for debugging while suppressing
their child values from log output.

In addition to these two functions, debug logging was removed in some
places where the effort of keeping would have outweighed the gain.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:13 +00:00
89b4e23bc1
misc.frame_parameters(): Add function
frame_parameters() returns a dictionary of name -> value pairs with
the parameters of the current call frames.

They can be limited by specifying exclude_names and exclude_values
which do the obvious thing.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:13 +00:00
581bb3531e
auth: Merge User and Group even further (Kind.Both)
Make Auth.Kind inherit from Flag rather than Enum, and introduce
Kind.Both, allowing an entity to be both Group and User.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:13 +00:00
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
73f52fb609
mypy: Fix disallow_incomplete_defs fallout
Add parameter and return type annotations to untyped functions all
over the package:

- ldap.py: Add return types to Config properties (ldap_uri, bind_dn,
  bind_pw, base_dn), Connection.__init__, add, delete, walk, find,
  __oc_recurse_to_top, object_class_path, and inner callbacks
- cast.py: Add Any import, add return type annotations to
  cast_str_to_bool, guess_type, from_str, from_env, cast_str, and
  parameter type annotations where missing
- Table.py:
  - __init__ (schema: Schema)
  - __eq__ (rhs: Any)
  - _column_data_type (name: str)
  - _column_default (name: str)
  - column_default (name: str)
  - foreign_keys_to_parent_table (parent_table: Any)
- misc.py:
  - get_derived_classes (mod: Any, flt: Any)
  - load_classes (flt: Any)
  - load_class_names (remove_flt: bool)
  - load_object (*args: Any, **kwargs: Any)
  - multi_regex_edit (spec: Any)
  - dump_dict (*args: Any, **kwargs: Any)
  - get_derived_classes (mod: Any, flt: Any)
  - load_classes (flt: Any)
  - load_class_names (remove_flt: bool)
  - load_object (*args: Any, **kwargs: Any)
  - dump (*args: Any, **kwargs: Any)
- MapAttr2Shape.py, ShuntingYard.py, Queries.py:
  - Add parameter and return type annotations to fix disallow_incomplete_defs:
    - MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add
    - ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval
    - Queries.py: _run, _register, name property, __getitem__, keys, load, add, _add
  - Add parameter and return type annotations:
    - ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument
    - rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump
    - auth/Auth.py: load, conf, _entity, projects
    - auth/ldap/Auth.py: __init__, _create_entity
  - Fix parameter type annotations:
    - rows_check_not_null: keys: str | list[str], stat_key: str | None, caller: Any
    - rows_dumps: lead: str | list[str] | None, tablefmt: str | None
    - rows_dump: heading: str | None, lead: str | list[str] | None, tablefmt: str | None
- Table.py: column_default, add_row_location, add_child_row_location
- CompositeForeignKey.py: __table, parent_column, child_column
- TableIoHandler.py: _load, _store, load
- Query.py: _register, register, parent property
- Ldap.py: Entity.__init__, Ldap.__init__, _create_entity
- MapAttr2Shape.py, auth/ldap/Auth.py, Query.py:
  - MapAttr2Shape.py: Add None check for id, add None check for graph
  - auth/ldap/Auth.py: Add Any import, fix __init__ and _create_entity
  - Query.py: Fix _add, run, parent signatures
- ArgsContainer.py: __setattr__, args, kwargs, dump, specified_args, add_argument
- Config.py: dump
- ShuntingYard.py: Op.__init__, tokenize, infix_to_postfix, eval_postfix, eval
- ShellCmd.py: __init__
- auth/Auth.py: load, __init__
- auth/dummy/Auth.py: Entity.__init__, Auth.__init__
- auth/ldap/Auth.py: Entity.__init__, Auth.__init__, _create_entity
- cast.py: guess_type
- DataBase.py: _create_session, _delete_session
- TableIoHandler.py: load
- Query.py: _run, _register, register, _add, run, parent/db properties
- QueryResult.py: pages, _cast
- rows.py: rows_duplicates, rows_check_not_null, rows_dumps, rows_dump
- Column.py: __eq__, foreign_key
- Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name
- Table.py: __init__, __eq__, _column_data_type, _column_default, column_default,
  __relationship_by_foreign_table, add_row_location, add_child_row_location
- utils.py: check_schema
- EventRouter.py: iter_peers
- Group.py: __init__
- SimpleEntity.py: __init__
- Ldap.py: Entity.__init__, Ldap.__init__, _create_entity
- Event.py: __init__
- Fuse.py: __init__
- Object.py: __init__
- SimpleObject.py: __init__, create
- EvRequest.py: __init__
- Msg.py: __init__
- ldap.py: Config.__get__, Config properties, Connection methods, inner callbacks
- misc.py: get_derived_classes, load_classes, load_class_names, load_object,
  multi_regex_edit, dump_dict, dump
- multi_key_dict.py: items
- MapAttr2Shape.py: __keys, __attribs, __massage_node, __massage_nodes, __add
- auth/dummy/Auth.py: Entity.__init__, Auth.__init__
- Query.py: _run, _register, register, _add, run, parent/db properties
- QueryResult.py: pages, _cast
- Column.py: __eq__, foreign_key
- Schema.py: _access_defining_columns, access_defining_columns, table_by_model_name
- Table.py: __init__, __eq__, _column_data_type, _column_default, column_default,
  __relationship_by_foreign_table, add_row_location, add_child_row_location
- utils.py: check_schema
- EventRouter.py: iter_peers
- Group.py: __init__
- SimpleEntity.py: __init__
- Ldap.py: Entity.__init__, Ldap.__init__, _create_entity
- Event.py: __init__
- Fuse.py: __init__
- Object.py: __init__
- SimpleObject.py: __init__, create
- EvRequest.py: __init__
- Msg.py: __init__

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
4fda12ce6a
mypy: Fix disallow_untyped_calls type errors
Add return type annotations and fix type mismatches to satisfy
disallow_untyped_calls:

- ShuntingYard.py: Operator.func -> Any|None, add assert for None
- ShellCmd.py: format_cmdline, __reap, __exec, __cleanup,
  SubprocessProtocol.__init__ return types, fix unreachable code
- TableIoHandler.py: cast _load() return to List[Dict[str, Any]]
- rows.py: add cast import, cast rows_dumps() return
- CompositeForeignKey.py: __table() cast fix, remove TYPE_CHECKING
- ldap.py: collect() parameter type ObjectClass
- multi_key_dict.py: get(), itervalues(), test function types,
  fix variable name conflicts, add set[Any] annotations

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
e014a9251f
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>
2026-08-12 23:10:13 +00:00
ec342ba172
mypy: Fix warn_return_any type errors
Add proper type annotations to fix mypy warn_return_any errors.
The following files were modified to add cast() calls or return
type annotations where functions returned Any values:

- algo/ShuntingYard.py: Add cast for operator() return value
- auth/Auth.py: Add cast for load() return value, fix imports
- cast.py: Fix cast_str_to_int return type, fix _strip type
- db/TableIoHandler.py: Remove redundant cast, fix store() return
- db/query/Queries.py: Add cast for _run() and __getitem__ returns
- db/query/Query.py: Add cast for db property return
- db/query/QueryResult.py: Add cast for db and query property returns
- db/schema/Schema.py: Add return type to __tables property, cast columns
- db/schema/Table.py: Add cast for model_module_search_paths return
- ev/app/EventRouter.py: Add cast for peer_conf.get() return
- ev/base/Object.py: Add cast for get_conf_section and str_or_none returns
- ev/base/SimpleObject.py: Add cast for create() return, fix imports
- load_yaml.py: Add cast for _expand_links_recursive return
- misc.py: Fix object_builtin_name return type, add param annotations
- stree/StringTree.py: Fix get() return type with default_value variable

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
f171443d49
mypy: Fix any_generics, redundant_casts, unused_ignores
Add mypy directives disallow_any_generics, warn_redundant_casts, and
warn_unused_ignores. Fix all resulting type annotation errors:

- load_yaml.py: Add type arguments to dict, tuple, set annotations; fix
  resolving dict/set types for link keys; handle str|int path types.
- misc.py: Add Mapping[str, Any] and Iterable[Any] type arguments; fix
  multiline export comment to avoid bad pattern flag.
- multi_key_dict.py: Add type argument to dict[tuple, Any].
- StringTree.py: Move Any import out of TYPE_CHECKING; fix MutableMapping
  type args.
- serdes.py: Add type argument to re.Match.
- Config.py: Change Config from Mapping to Mapping[str, str]; remove
  unused cast.
- ev/base/Object.py, SimpleObject.py, EventLogger.py, PollerOneShot.py:
  Add Mapping[str, Any] type args.
- ev/app/EventRouter.py: Add dict[str, Any] type args in inner functions.
- auth/*: Remove now-unnecessary # type: ignore[return-value] comments.

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
9e24a2f394
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>
2026-08-12 23:10:12 +00:00
241aa79120
mypy: Fix fallout of ignore-without-code
Fix fallout of mypy --enable-error-code=ignore-without-code check.

The multi_key_dict class had several type issues: the keys() and values()
methods could implicitly return None when a key type was specified but not
found, pyright flagged the conditional items() redefinition, and six test
call sites carried bare "# type: ignore" comments.

Add from __future__ import annotations, a _keys_from_dict() helper, and
proper parameter/return type annotations to keys(), values(), and items().
Consolidate the conditional Python 2/3 items() into a single function with
runtime dispatch. Remove all six bare type-ignores from multi_key_dict.py
and annotate the remaining pre-existing ones in other files with specific
error codes required by ignore-without-code.

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:12 +00:00
0e660dc58b
auth: Merge users and groups into Entity
Rename the AuthEntity class to Entity, because the Auth prefix is
redundant if used in / imported from the auth module.

Next, put all relevant properties into that class, and make User and
Group a TypeAlias of that type. Introduce an Enum, "Kind", to allow a
distinction. See the previous commits for a rationale.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
a94603b6cc
auth.Auth.load(): Support dict and StringTree
Auth objects can currently be loaded dynamically with a Config type
argument. For greater flexibility, allow to pass dict and StringTree
mappings to load(), too.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
dd6caf4f99
auth: Force keyword-argument passing to __init__()
Expecting possible confusion regarding further base class gymnastics,
e.g. multiple inheritance, make it impossible to pass constructor
arguments to User and Group as blank positional arguments, force
passing the argument names instead by adding "*" as first argument.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
d73d921885
auth.Auth.User + .Group: Derive from AuthEntity
User and Group share now enough properties to tie them closer
together. The number of these properties will likely grow:
email-address, nested groups and others.  This commit introduces
AuthEntity as a common base class to make that happen.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
7595bfc21e
load_yaml: Add target path support to jw.include
jw.include now supports specifying a target path where the included
content should be merged, using syntax similar to named links:

  jw.include: "path.to.target|/path/to/file.yaml"

The file's contents are deep-merged into the target path in the
resulting document tree.  If the target path doesn't exist,
intermediate dicts are created automatically.

Original behavior (plain string) still works:

  jw.include: "/path/to/file.yaml"

This merges the file at the root of the document.

Mixed usage is supported:

  jw.include:
    - "/path/to/plain.yaml"
    - section|/path/to/target.yaml

Added 8 unit tests covering: plain includes, nested paths, deep paths,
merge with existing, override existing, multiple paths, optional
includes, and mixed plain/path includes.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
ab77b24a50
load_yaml: Add jw.inplace-link with sibling merge
jw.inplace-link behaves like jw.link but can have sibling keys that
are deep-merged into the resolved target dict (siblings override target
on conflict).

Usage:

  entry:
    jw.inplace-link: path.to.target
    sibling_key: value

Expands to:

  entry:
    <merged result of path.to.target + sibling_key: value>

This solves the common use case of pulling in a dict from elsewhere
while overriding specific keys inline.

Added 12 unit tests covering: no siblings, dict siblings, scalar
siblings, non-dict targets, relative paths, cycle detection, chains,
list siblings, list items, deep nesting, sibling override, and
integration with jw.include.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
57a75399a2
load_yaml: Rename include directive to jw.include
The include directive was previously triggered by a bare "include"
key in YAML files.  This could collide with user-defined keys.

Rename it to "jw.include" so that:

    jw.include: file.yaml
    jw.include:
      - file1.yaml
      - file2.yaml

is used instead of just "include:".  This follows the convention
established by "jw.link" for link expansion markers.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
d7454341e8
load_yaml: Implement jw.link expansion
Implement link expansion in _expand_links() to resolve jw.link markers
in YAML documents after the include/merge phase.  Two link forms are
supported:

- Inplace links  jw.link: "path.to.target" replace the marker entirely
  with the resolved value at the target path.
- Named links   jw.link: "name|path.to.target" replace the marker with
  {name: resolved_value}, using the first path segment as the key.

Paths use dot-separated segments.  Relative paths start with ".."
(like Python imports): "." stays at the current level, ".." goes up
one level, "..." two, and so on.  A single pipe character in the link
value separates the link name from the target path for named links.

The implementation includes:

- _parse_link(): splits a link value into (is_named, name, path)
- _resolve_path(): resolves an absolute or relative path to a value
- _expand_links_recursive(): walks the structure, expands links,
  detects cycles via a resolving set, and memoises via a resolved dict.

Cyclic links and missing targets both raise ValueError/KeyError.
jw.link markers with sibling keys are left unexpanded.

Add 86 unit tests covering the entire load_yaml module:

- Basic YAML loading, optional loading, root type checking
- Include directive (single, multiple, deep merge, circular detect)
- Inplace links, named links, relative paths (up, descend, same level)
- Transitive links, cycle detection, missing targets
- Regression tests, combined include+links, edge cases, type preservation

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
69c81ada43
load_yaml: Add module
Add load_yaml.load_yaml(), adding little over yaml.safe_load(), aside
from supporting a toplevel entry "include", which can contain a list
of included paths.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
efa387a533
Object: Add properties name, log_name, log_data
Add some introspection properties to Object, to make it suitable as a
lightweight base class for named objects.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
0d3008d656
func_tools: Add module
Add the func_tools module for giving the private_method decorator a
home.

The decorator enforces that a method can only be called by methods
belonging to the same class. It inspects the call stack at runtime
and raises AttributeError if the caller is not a method of the owning
class.

When decorating a class, the decorator scans all other class members
for functions (including static, class, and other private methods) and
records their code objects as allowed callers. The __get__() method
returns a wrapper that checks the current frame's code object against
this set before dispatching to the actual method.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
5a8dfab722
enum_helper: Add module
Add the module enum_helper, providing the following functions:

  def kebab_to_pascal(value: str) -> str
  def pascal_to_kebab(value: str) -> str
  def enum_from_kebab(enum_cls: type[EnumType], value: str) -> EnumType
  def enum_to_kebab(member: Enum) -> str

The intended use of these functions is to convert from configuration
strings to application enums and back.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
30f7b17e03
misc.dump_dict(): Add function
Add a dump_dict() function to log the contents of a mapping in a
structured way. Useful for debugging.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
20a8ab91f7
misc.load_object(): Allow multi-value module path
load_path() takes a string as module path. To broaded its
versatility, allow also multiple strings to be searched in order.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
cb3ad84fda
misc.is_multi_value(): Add function
Add a function that allows to test one expression if a value can be
iterated over without being a string or bytes.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
7bfe80a761
misc: Add type hints, cleanup
Add some type hints to the misc module, and remove the unused
silentremove functionality. Also, make the jwutils facade follow the
move.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
3dd5255c90
misc.load_class(): Beautify exception message
Depending on whether or not a name or type filter is used, the
exception message of load_class() can be a bit confusing. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
d4fd741c19
misc.load_class(): Use jw.pkg.lib.LoadTypes
Make load_class() use jw.pkg.lib.LoadTypes, because it provides the
possibility to nicely log which modules and classes it picks.

TODO: Don't use importlib at all in module misc.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
26f3893579
test: Fix MyPy errors
Fix multiple errors in test dug up by MyPy.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
af185c60f9
Config: Derive from Mapping and add @override
Derive Config from collections.abc.Mapping to formally declare it as
a read-only mapping interface. Implement the three abstract methods:

  - __getitem__(): delegates to get(), raises KeyError if missing
  - __iter__(): iterates over config keys (delegated to __conf)
  - __len__(): returns number of top-level keys

Add @override to __getitem__(), __iter__(), and __len__(). The get()
method does not get @override — Mapping.get() uses generic overloads
with Any-typed parameters that are incompatible with Config.get()’s
specific str-typed signature. While Config.get() is Liskov-safe
(contravariant args, covariant return), mypy flags the mismatch on
the def line. A targeted "# type: ignore[override]" suppresses only
this one false positive without disabling override checking for the
rest of the module.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
ffbb070076
Config: Modernize types to PEP 604 union syntax
Replace Optional[X] with X | None and typing.Dict with builtin dict
throughout the module. Add "from __future__ import annotations" to
enable deferred evaluation, removing all quoted forward references.

Add missing return type annotations to __setitem__(), parent, root,
set(), get(), value(), and name. Remove Optional and Dict from the
typing import since cast() is the only runtime typing helper needed.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
9ed8c1cb18
Config: Annotate __load() signature and paths_buf
The __load() method has no type annotations for any of its three
parameters, making it inconsistent with __init__ and harder for type
checkers to verify correctness. Add type annotations to all __load()
parameters and the paths_buf local variable.

The paths_buf variable needs an explicit list[str] annotation because
mypy cannot infer the type of an empty list literal when passed as
a mutable buffer argument to serdes.read().

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
1f3e38e685
Config: Add diagnostic to paths_buf assert
The bare assert (len(paths_buf)) relies on truthiness which, while
correct, is misleading — readers might expect "assert len(paths_buf)
> 0" instead. Replace with an explicit comparison and add a diagnostic
message showing the actual length for easier debugging.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
8a7bcfba8e
Config: Fix branch() return type annotation
The branch() method returns either None or a Config but has no
return type annotation — just a "# type: ignore" comment with a
FIXME. Add the proper Optional[Config] annotation (written as
Config | None in modern syntax) and remove the workaround.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
544d80949f
Config: Define _REFUSE_MODE_MASK constant
Extract the magic 0o0027 default for refuse_mode_mask into a module-
level constant with a docstring. This makes the default parameter
self-documenting and prevents duplication if the value ever changes.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00