Commit graph jw-python/src/python/jw/util/Config.py
Author SHA1 Message Date
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
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
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
c7b4a6e118
Config: Replace __is_abs() with os.path.isabs()
The __is_abs() helper duplicates os.path.isabs() logic. Replace it
with the standard library function, guarding for None/empty strings
to match the original helper safety behavior.

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
f9f10f9b9e
Config: Fix search_dirs env var parsing into dirs
When search_dirs comes from an environment variable, the __load()
method iterates over each character of the colon-separated string
instead of treating it as a list of directory paths. This produces
nonsensical glob paths like "h/", "o/", "m/", etc.

Fix by splitting the env var value into a list before assigning it
to the search_dirs variable.

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
e9845b5a1f
Makefile: Include py-topdir.mk
Include py-topdir.mk, which entails loads of fallout from make check.
Fix it.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-12 04:55:47 +02:00
a2684dd601
jwutils: Move to jwutils -> jw.util
Move all implementation source code from the jwutils module to
jw.util. For compatibility with existing Python modules, keep a thin,
autogenerated compatibility shim under jwutils.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-06-11 23:10:25 +00:00
Renamed from tools/python/jwutils/Config.py (Previous history)