Skip to content

refactor: split large generator methods + write_block for fixed-shape code#149

Merged
devdanzin merged 1 commit into
mainfrom
generator-method-splits
Jun 30, 2026
Merged

refactor: split large generator methods + write_block for fixed-shape code#149
devdanzin merged 1 commit into
mainfrom
generator-method-splits

Conversation

@devdanzin

Copy link
Copy Markdown
Owner

Tackles the remaining generator tech-debt items (under #106), after the indentation-API migration (#145#148).

_write_main_fuzzing_logic (was cognitive complexity 73)

Now a thin orchestrator that delegates to focused helpers:

  • _write_fuzzing_logic_preamble — module alias, thread/async registries, runtime imports
  • _write_function_fuzzing_loop + _write_one_function_fuzz — the per-call OOM-sequence / OOM-sweep / standard dispatch (was a deeply-nested if/else in the loop body)
  • _write_oom_class_fuzzing_loop, _write_class_fuzzing_loop, _write_object_fuzzing_loop

_generate_and_write_call

Extracted:

  • _pick_call_arg_count — the arg-count distribution (0 / 1 / max+1 / in-range)
  • _write_result_deep_dive — opt-in --deep-dive recursion
  • _write_target_func_fetch, _write_thread_call_wrapper, _write_async_call_wrapper

write_block for fixed-shape code

The fully-static compare_results helper and the two concurrency-finalization blocks (thread start/join, async runner) now emit as single dedented blocks instead of dozens of self.write calls — the generated code reads as actual Python in the source. (The header/imports and tricky-definitions methods already used dedent/write_block.)

Verification — all behaviour-preserving

  • Golden snapshot (default path) unchanged.
  • OOM and deep-dive/thread/async paths (not in the golden net) confirmed byte-identical with the before/after harnesses under a pinned PYTHONHASHSEED.
  • Suite 328 OK; ruff check + ruff format --check clean.

🤖 Generated with Claude Code

…hape code

Reduces the two highest-complexity methods in write_python_code.py and adopts
write_block for the remaining line-by-line static emit runs (under #106; follows
the indentation-API migration #145#148).

_write_main_fuzzing_logic: was a single cognitive-73 method. Now a thin
orchestrator delegating to _write_fuzzing_logic_preamble,
_write_function_fuzzing_loop (+ _write_one_function_fuzz for the per-call
OOM/standard dispatch), _write_oom_class_fuzzing_loop, _write_class_fuzzing_loop,
and _write_object_fuzzing_loop.

_generate_and_write_call: extracted _pick_call_arg_count (the arg-count
distribution), _write_result_deep_dive, _write_target_func_fetch,
_write_thread_call_wrapper, and _write_async_call_wrapper.

write_block: the fully-static compare_results helper and the two
concurrency-finalization blocks (thread start/join, async runner) now emit as
single dedented blocks instead of dozens of self.write calls.

All behaviour-preserving. Verified byte-identical: the golden snapshot
(default path) is unchanged, and the OOM + deep-dive/thread/async paths (not in
the golden net) were confirmed byte-identical with the before/after harnesses
under a pinned PYTHONHASHSEED. Suite 328 OK; ruff check + format clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@devdanzin devdanzin merged commit f01ef12 into main Jun 30, 2026
2 checks passed
@devdanzin devdanzin deleted the generator-method-splits branch June 30, 2026 09:16
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.

1 participant