You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Skipping 'future' imports is correct, but consider whether to also skip adding removal operations for them to avoid unintended cleanup if they exist in destination; verify RemoveImportsVisitor behavior when 'future' is present.
# Skip __future__ imports as they cannot be imported directly# __future__ imports should only be imported with specific objects i.e from __future__ import annotationsifmod=="__future__":
continueifmodnotindotted_import_collector.imports:
AddImportsVisitor.add_needed_import(dst_context, mod)
RemoveImportsVisitor.remove_unused_import(dst_context, mod)
aliased_objects=set()
The 'aliased_objects' set prevents duplicate imports, but it relies on f"{mod}.{name}" matching. Confirm that it covers both 'from X import Y as Z' and potential nested objects (e.g., submodules) and that it doesn’t suppress needed imports when alias names overlap with real objects.
aliased_objects=set()
formod, alias_pairsingatherer.alias_mapping.items():
foralias_pairinalias_pairs:
ifalias_pair[0] andalias_pair[1]: # Both name and alias existaliased_objects.add(f"{mod}.{alias_pair[0]}")
formod, obj_seqingatherer.object_mapping.items():
forobjinobj_seq:
if (
f"{mod}.{obj}"inhelper_functions_fqnordst_context.full_module_name==mod# avoid circular deps
):
continue# Skip adding imports for helper functions already in the contextiff"{mod}.{obj}"inaliased_objects:
continue
Using testcase.name in loop_index parsing now checks for None, which is good; ensure parsing "[ " with space matches actual pytest param formatting and won’t raise on unexpected patterns.
iftest_config.test_framework=="pytest":
loop_index=int(testcase.name.split("[ ")[-1][:-2]) iftestcase.nameand"["intestcase.nameelse1iflen(testcase.result) >1:
logger.debug(f"!!!!!Multiple results for {testcase.nameor'<None>'} in {test_xml_file_path}!!!")
iflen(testcase.result) ==1:
message=testcase.result[0].message.lower()
if"failed: timeout >"inmessage:
timed_out=Trueelse:
testcase.result[0].message may be None; calling .lower() will raise an exception. Guard against None by defaulting to an empty string before lowering. This avoids crashes when parsing flaky junit outputs.
if len(testcase.result) == 1:
- message = testcase.result[0].message.lower()+ raw_msg = testcase.result[0].message+ message = (raw_msg or "").lower()
if "failed: timeout >" in message:
timed_out = True
Suggestion importance[1-10]: 7
__
Why: This adds a safe guard for a potential None message before .lower(), preventing crashes on flaky XML; it's accurate and modestly improves robustness.
Medium
Safely lower possibly None message
Similar to the pytest branch, .message can be None. Ensure safe handling by coalescing to an empty string before .lower(). This prevents exceptions on junit results lacking a message.
if len(testcase.result) == 1:
- message = testcase.result[0].message.lower()+ raw_msg = testcase.result[0].message+ message = (raw_msg or "").lower()
if "timed out" in message:
timed_out = True
Suggestion importance[1-10]: 7
__
Why: Mirrors the safety improvement in the unittest branch; accurate and prevents errors if .message is None, with moderate impact.
Medium
General
Avoid fragile duplicate-check logic
The dotted_import_collector.imports likely stores fully-qualified import entries, so checking mod directly may never match and cause duplicate imports. Compare against a normalized set of module-only imports or rely on the visitor's internal de-duplication logic consistently. This prevents redundant import statements being added.
for mod in gatherer.module_imports:
# Skip __future__ imports as they cannot be imported directly
# __future__ imports should only be imported with specific objects i.e from __future__ import annotations
if mod == "__future__":
continue
- if mod not in dotted_import_collector.imports:- AddImportsVisitor.add_needed_import(dst_context, mod)+ # Always request add; the visitor will avoid duplicates if already present+ AddImportsVisitor.add_needed_import(dst_context, mod)
RemoveImportsVisitor.remove_unused_import(dst_context, mod)
Suggestion importance[1-10]: 4
__
Why: The suggestion is plausible but speculative; it assumes dotted_import_collector.imports structure without evidence. Removing the check may cause unnecessary operations; impact is minor and correctness uncertain.
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
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.
PR Type
Bug fix, Tests
Description
Skip invalid and future imports
Handle None aliases safely
Reduce noisy warnings to debug
Add tests for alias edge cases
Diagram Walkthrough
File Walkthrough
code_extractor.py
Safer import insertion with alias and future handlingcodeflash/code_utils/code_extractor.py
__future__as module.parse_test_output.py
Robust XML parsing with quieter loggingcodeflash/verification/parse_test_output.py
testcase.nameis None.test_code_extractor_none_aliases_exact.py
Tests for import alias edge casestests/test_code_extractor_none_aliases_exact.py