refactor: split large generator methods + write_block for fixed-shape code#149
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-nestedif/elsein the loop body)_write_oom_class_fuzzing_loop,_write_class_fuzzing_loop,_write_object_fuzzing_loop_generate_and_write_callExtracted:
_pick_call_arg_count— the arg-count distribution (0 / 1 / max+1 / in-range)_write_result_deep_dive— opt-in--deep-diverecursion_write_target_func_fetch,_write_thread_call_wrapper,_write_async_call_wrapperwrite_blockfor fixed-shape codeThe fully-static
compare_resultshelper and the two concurrency-finalization blocks (thread start/join, async runner) now emit as single dedented blocks instead of dozens ofself.writecalls — the generated code reads as actual Python in the source. (The header/imports and tricky-definitions methods already useddedent/write_block.)Verification — all behaviour-preserving
PYTHONHASHSEED.ruff check+ruff format --checkclean.🤖 Generated with Claude Code