Skip to content

Feature: Add AST-based unused variable detection#1014

Open
himnishag wants to merge 13 commits into
imDarshanGK:mainfrom
himnishag:feature/python-unused-variable-detection
Open

Feature: Add AST-based unused variable detection#1014
himnishag wants to merge 13 commits into
imDarshanGK:mainfrom
himnishag:feature/python-unused-variable-detection

Conversation

@himnishag

@himnishag himnishag commented Jun 11, 2026

Copy link
Copy Markdown

Description

This PR adds AST-based unused variable detection to the Python analyzer.

What was added

  • Implemented detect_unused_variables() using Python's built-in AST module.
  • Detects variables that are assigned but never used later in the code.
  • Ignores intentionally unused variables prefixed with _.
  • Integrated the new detection into the main analyze() pipeline.
  • Added unit tests to verify detection and prevent false positives.

Example

x = 10
y = 20
print(x)

Detected issue:

  • y is assigned but never used.

Related Issue

Fixes # 45

Screenshot 2026-06-11 155008

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
  • 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

python -m pytest tests/test_ast_analyzer.py

============================= test session starts =============================
collected 43 items

tests/test_ast_analyzer.py ........................................... [100%]

============================= 43 passed in 0.18s =============================
Screenshot 2026-06-11 155102

@himnishag himnishag requested a review from imDarshanGK as a code owner June 11, 2026 10:21
@imDarshanGK

Copy link
Copy Markdown
Owner

@himnishag issue number?

@himnishag

Copy link
Copy Markdown
Author

issue number is

Fixes #791

@himnishag himnishag force-pushed the feature/python-unused-variable-detection branch from 23e3954 to 44e326a Compare June 18, 2026 13:16
@himnishag

Copy link
Copy Markdown
Author

@imDarshanGK

I have fixed the lint and formatting issues and pushed the latest changes.

Could you please approve the pending workflows and review the PR?

Thank you.

@imDarshanGK imDarshanGK left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himnishag

Copy link
Copy Markdown
Author

@imDarshanGK

I have fixed the formatting issue and pushed the latest commit (Apply CI black formatting).

The workflows are currently awaiting maintainer approval. Could you please approve the pending workflows and re-review the PR?

Thank you.

@himnishag himnishag requested a review from imDarshanGK June 19, 2026 09:11
@imDarshanGK

Copy link
Copy Markdown
Owner

@himnishag resolve conflicts

@himnishag

Copy link
Copy Markdown
Author

Hi @imDarshanGK,

I've resolved the merge conflicts in the PR and merged the latest main into my branch. The conflicting files (main.py, database.py, and test_history.py) have been resolved and pushed.

Could you please review it again? Let me know if any further changes are needed.

Thanks!

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.

2 participants