Skip to content

Fix #1135: Connect PythonASTAnalyzer to the analysis pipeline#1162

Open
anushkagupta200615-jpg wants to merge 1 commit into
imDarshanGK:mainfrom
anushkagupta200615-jpg:fix-issue-1135
Open

Fix #1135: Connect PythonASTAnalyzer to the analysis pipeline#1162
anushkagupta200615-jpg wants to merge 1 commit into
imDarshanGK:mainfrom
anushkagupta200615-jpg:fix-issue-1135

Conversation

@anushkagupta200615-jpg

Copy link
Copy Markdown

Description

This PR modifies backend/app/services/ast_analyzer.py to correctly call analyze_python_ast(source) within the main analyze() function. Previously, the PythonASTAnalyzer class was instantiated but never executed, skipping vital checks for mutable default arguments, bare except: blocks, eval/exec usage, and builtin variable shadowing.

By appending the results of analyze_python_ast(source) to the issues list, these AST-based checks are now successfully integrated into the analysis pipeline.

Related Issue

Fixes #1135

Type of change

  • Bug fix
  • New feature / enhancement
  • Documentation update
  • Test addition
  • Refactor

Checklist

  • I have read CONTRIBUTING.md
  • My branch is up to date with main
  • I have run pytest -v and all tests pass (for ast_analyzer.py)
  • I have not introduced duplicate issues or features
  • My PR title follows the format: feat/fix/docs/test: short description
  • I have added tests for new features (Level 2 and 3 issues)
  • No hardcoded secrets or API keys in my code
  • This PR is linked to a GSSoC 2026 issue

Screenshots (if frontend change)

N/A

Test evidence

$ pytest backend/tests/test_ast_analyzer.py -v
============================= test session starts =============================
platform win32 -- Python 3.10.0, pytest-9.1.1, pluggy-1.6.0
collected 40 items

backend/tests/test_ast_analyzer.py::test_mutable_default_list PASSED     [  2%]
backend/tests/test_ast_analyzer.py::test_mutable_default_dict PASSED     [  5%]
backend/tests/test_ast_analyzer.py::test_mutable_default_set PASSED      [  7%]
backend/tests/test_ast_analyzer.py::test_no_mutable_default_with_none PASSED [ 10%]
backend/tests/test_ast_analyzer.py::test_no_mutable_default_immutable PASSED [ 12%]
backend/tests/test_ast_analyzer.py::test_bare_except_detected PASSED     [ 15%]
backend/tests/test_ast_analyzer.py::test_bare_except_line_number PASSED  [ 17%]
backend/tests/test_ast_analyzer.py::test_specific_except_not_flagged PASSED [ 20%]
backend/tests/test_ast_analyzer.py::test_except_exception_not_flagged PASSED [ 22%]
backend/tests/test_ast_analyzer.py::test_eval_detected PASSED            [ 25%]
backend/tests/test_ast_analyzer.py::test_exec_detected PASSED            [ 27%]
backend/tests/test_ast_analyzer.py::test_eval_line_number PASSED         [ 30%]
backend/tests/test_ast_analyzer.py::test_eval_severity_is_error PASSED   [ 32%]
backend/tests/test_ast_analyzer.py::test_no_false_positive_ast_literal_eval PASSED [ 35%]
backend/tests/test_ast_analyzer.py::test_shadow_list PASSED              [ 37%]
backend/tests/test_ast_analyzer.py::test_shadow_id PASSED                [ 40%]
backend/tests/test_ast_analyzer.py::test_shadow_len PASSED               [ 42%]
backend/tests/test_ast_analyzer.py::test_shadow_print PASSED             [ 45%]
backend/tests/test_ast_analyzer.py::test_no_shadow_for_user_names PASSED [ 47%]
backend/tests/test_ast_analyzer.py::test_unreachable_after_return PASSED [ 50%]
backend/tests/test_ast_analyzer.py::test_unreachable_after_raise PASSED  [ 52%]
backend/tests/test_ast_analyzer.py::test_reachable_code_not_flagged PASSED [ 55%]
backend/tests/test_ast_analyzer.py::test_unreachable_line_number PASSED  [ 57%]
backend/tests/test_ast_analyzer.py::test_syntax_error_returns_issue PASSED [ 60%]
backend/tests/test_ast_analyzer.py::test_syntax_error_severity PASSED    [ 62%]
backend/tests/test_ast_analyzer.py::test_syntax_error_does_not_crash PASSED [ 65%]
backend/tests/test_ast_analyzer.py::test_clean_code_returns_no_ast_issues PASSED [ 67%]
backend/tests/test_ast_analyzer.py::test_issue_shape_has_required_fields PASSED [ 70%]
backend/tests/test_ast_analyzer.py::test_unreachable_code PASSED         [ 72%]
backend/tests/test_ast_analyzer.py::test_unused_import PASSED            [ 75%]
backend/tests/test_ast_analyzer.py::test_unused_argument PASSED          [ 77%]
backend/tests/test_ast_analyzer.py::test_clean_code_no_false_positives PASSED [ 80%]
backend/tests/test_ast_analyzer.py::test_correct_line_number_unreachable PASSED [ 82%]
backend/tests/test_ast_analyzer.py::test_self_not_flagged_as_unused PASSED [ 85%]
backend/tests/test_ast_analyzer.py::test_underscore_param_not_flagged PASSED [ 87%]
backend/tests/test_ast_analyzer.py::test_used_alias_not_flagged PASSED   [ 90%]
backend/tests/test_ast_analyzer.py::test_too_many_returns_exact_boundary PASSED [ 92%]
backend/tests/test_ast_analyzer.py::test_unreachable_only_flags_after_not_before PASSED [ 95%]
backend/tests/test_ast_analyzer.py::test_nested_function_returns_not_counted_in_outer PASSED [ 97%]
backend/tests/test_ast_analyzer.py::test_deep_nesting_exact_boundary PASSED [100%]

============================= 40 passed in 0.15s ==============================

This commit modifies ast_analyzer.py to correctly call analyze_python_ast(source) so that the PythonASTAnalyzer's results are actually included in the final issues list.
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.

Bug: PythonASTAnalyzer is dead code and disconnected from the analysis pipeline

1 participant