Skip to content

Refactor step-function dispatch (_build_step_func) #30

@jc-macdonald

Description

@jc-macdonald

Refactor the _build_step_func dispatch in core_solver.py (around L1850) to reduce cyclomatic complexity.

Problem

The current dispatch logic triggers C901 (too complex) and is suppressed with a noqa comment. As solver methods grow, this will become increasingly unmaintainable.

Proposed approach

Replace the if/elif chain with a _PLAN_TO_STEP_FUNC mapping dict as Tim suggested:

_PLAN_TO_STEP_FUNC: dict[MethodName, Callable] = { ... }

if (step_func := _PLAN_TO_STEP_FUNC.get(plan.method)) is not None:
    if plan.jacobian is None:
        raise RuntimeError(_INTERNAL_ERROR_OP_AXIS_MSG)
    return step_func(rhs_func, step=step, jacobian=plan.jacobian)

Related

Ref: PR #18 review by @TimothyWillard (L1850, L1918)

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode reorganization without behavior change

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions