Skip to content

Break up RemoteRunner.call_process and repair its error messages - #745

Open
appleweiping wants to merge 1 commit into
nlpie:mainfrom
appleweiping:fix/399-call-process-complexity
Open

Break up RemoteRunner.call_process and repair its error messages#745
appleweiping wants to merge 1 commit into
nlpie:mainfrom
appleweiping:fix/399-call-process-complexity

Conversation

@appleweiping

Copy link
Copy Markdown

Fixes #399.

RemoteRunner.call_process reports C901 ... is too complex (14) against the --max-complexity=10 the lint job uses. Most of that came from two error-translation blocks nested inside the happy path.

This extracts _rpc_error_message, _handle_rpc_error and _process_remotely as methods, plus _group_created_indices as a module-level function, leaving call_process as the request/response flow. The grouping loop becomes a setdefault instead of a try/except KeyError.

The restructuring itself changes no behaviour: pytest python/tests reports the same 242 passed, 10 skipped before and after.

Two error paths that never worked

Pulling the block apart made both visible.

The UNAVAILABLE advice was being discarded. It was written as:

msg = f'Failed to connect to "{self.processor_name}", check '
"that the service is running and the address is "
"correctly configured."

The second and third lines are expression statements, not continuations of the assignment, so they evaluate and are thrown away. Operators saw a message that stopped mid-sentence at check . They are now part of the string.

The closed-channel message could never be produced. The check was e == ValueError('Cannot invoke RPC on closed channel!'). ValueError defines no __eq__, so this is always False:

>>> ValueError('x') == ValueError('x')
False

It now compares the type and str(e).

Testing

Adds python/tests/processing/test_runners.py covering both messages, the absence of a specific message for other status codes, and the index grouping — 5 tests, suite goes to 247 passed / 10 skipped.

These pin the corrected behaviour rather than reproducing the old one: the message construction was inline inside call_process, so there was nothing to assert against before the extraction. The evidence that the old paths were dead is the language behaviour shown above.

Running the lint job's flags over python goes from 4 findings to 3. The two that remain are pre-existing E501/E303 in deployment.py, untouched here.

🤖 Generated with Claude Code

`RemoteRunner.call_process` reports C901 at complexity 14 against the
`--max-complexity=10` the lint job uses, which is nlpie#399. Most of that came from
two error-translation blocks nested inside the happy path.

Extracts `_rpc_error_message`, `_handle_rpc_error` and `_process_remotely` as
methods, and `_group_created_indices` as a module-level function, leaving
`call_process` as the request/response flow. The grouping loop also becomes a
`setdefault`, replacing a try/except KeyError. No behaviour changes from the
restructuring itself: the suite reports the same 242 passed and 10 skipped
before and after.

Restructuring the block surfaced two error paths that never worked:

The UNAVAILABLE advice was written as

    msg = f'Failed to connect to "{name}", check '
    "that the service is running and the address is "
    "correctly configured."

The second and third lines are expression statements, not continuations, so
they were discarded and operators saw a message ending mid-sentence at
"check ". They are now part of the string.

The closed-channel case tested `e == ValueError('Cannot invoke RPC on closed
channel!')`. `ValueError` does not define `__eq__`, so that comparison is
always False and the intended "Channel was closed when trying to process."
message could never be produced. It now compares the type and `str(e)`.

Adds tests covering both messages, the absence of a message for other status
codes, and the index grouping. These pin the corrected behaviour; the previous
behaviour could not be asserted against, since the logic was inline.

Lint on `python` with the CI flags goes from 4 findings to 3. The two
remaining, both in `deployment.py`, are pre-existing and untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@appleweiping

appleweiping commented Sep 7, 2026

Copy link
Copy Markdown
Author

Validated the latest head aa12cc5 locally.

  • The focused runner test file passed all 5 tests.
  • Python compilation passed for the updated runner module.
  • The diff check passed.

This covers the refactored RemoteRunner call, the repaired error messages, and the grouping helper. Please review the updated branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flake8 complexity violation in RemoteRunner.call_process

1 participant