Commit graph jw-python/src/python/jw/util/auth
Author SHA1 Message Date
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
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
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
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