Fix coverage function identification using qualified names - #1457
Merged
Conversation
The coverage system was using bare function_name (e.g., "__init__") instead of qualified_name (e.g., "HttpInterface.__init__"), causing it to match the wrong class's method when multiple classes define the same method name (like __init__). Changes: - function_optimizer.py: pass qualified_name to parse_test_results - build_fully_qualified_name: skip re-qualifying already-qualified names - extract_dependent_function: compare using bare name from qualified input - grab_dependent_function_from_coverage_data: replace substring match with exact or dot-bounded suffix match
…ytest_parallelization - PrComment.py: rename loop variable to avoid shadowing the result dict - concolic_utils.py: add None guard for tree, annotate new_body as list[ast.stmt] - pytest_parallelization.py: separate set/list variables, annotate result_groups
Contributor
PR Review SummaryPrek Checks✅ All checks pass. One formatting issue was auto-fixed by ruff format in Mypy Checks✅ All 6 changed files (excluding Code ReviewNo critical issues found. The changes are well-focused and correct:
Test Coverage
Coverage analysis:
Last updated: 2026-02-12T05:30:00Z |
The optimized code achieves a **197% speedup (28.5ms → 9.57ms)** through three strategic optimizations that dramatically reduce expensive AST parsing operations: ## Key Optimizations **1. Early String Filtering (74% time reduction in parsing)** The optimization adds a lightweight heuristic check `if "def" not in code_string.code` before calling `ast.parse()`. Since function definitions require the `def` keyword, strings without it can be skipped entirely. In the profiler results, this reduced AST parsing from 32.5ms (80.5% of original runtime) to 9.9ms (74.2% of optimized runtime). The test results show dramatic improvements for large-scale scenarios: - `test_large_scale_many_code_strings_single_dependent_function`: **6839% faster** (4.45ms → 64.1μs) - `test_large_scale_with_preexisting_objects_and_many_irrelevant_entries`: **4193% faster** (2.26ms → 52.7μs) **2. Hoisted Main Function Name Computation** Moving `bare_main` calculation outside the loop (from line 13 to line 10) eliminates redundant string operations that were executed once per code string. This simple reordering saves repeated `rsplit()` calls. **3. Early Exit on Multiple Dependencies** The optimization checks `if len(dependent_functions) > 1: return False` immediately after adding each function name, rather than waiting until all code strings are processed. This allows the function to short-circuit as soon as it detects the failure condition, avoiding unnecessary AST parsing of remaining code strings. ## Why This Matters Based on the function references, `extract_dependent_function` is called during test generation workflows where it processes potentially hundreds or thousands of code strings. The optimization is particularly effective when: - Most code strings don't contain function definitions (common in test contexts with imports, variables, etc.) - Multiple dependent functions exist (early exit prevents wasted parsing) - Code bases have many test-related code strings that aren't function definitions The optimizations preserve exact behavior while intelligently avoiding expensive operations, making the code significantly more efficient in real-world usage patterns where the function processes large volumes of code strings.
Contributor
⚡️ Codeflash found optimizations for this PR📄 197% (1.97x) speedup for
|
…2026-02-12T04.58.15 ⚡️ Speed up function `extract_dependent_function` by 197% in PR #1457 (`fix-coverage-qualified-name`)
Contributor
|
This PR is now faster! 🚀 @KRRT7 accepted my optimizations from: |
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.
Summary
function_name(e.g.,__init__) instead ofqualified_name(e.g.,HttpInterface.__init__) to identify the main function, causing it to match the wrong class's method when multiple classes define methods with the same namebuild_fully_qualified_namenow skips re-qualifying already-qualified namesextract_dependent_functioncompares using the bare portion of a qualified main function namegrab_dependent_function_from_coverage_datafallback search now uses exact or dot-bounded suffix match instead of substring matchTest plan
build_fully_qualified_name,extract_dependent_function, andgrab_dependent_function_from_coverage_dataHttpInterface.__init__that has multiple__init__methods in dependencies