Skip to content

Conversation

@shivasurya
Copy link
Owner

@shivasurya shivasurya commented Nov 4, 2025

Summary

Implements Python statement extraction from AST to support intra-procedural dataflow analysis. This is part 2 of the intra-procedural dataflow feature.

Changes

  • Add statement extraction for Python functions
  • Extract assignments, calls, and returns with def-use information
  • Comprehensive test coverage (87.3%)

Testing

  • 20+ tests covering all statement types
  • All tests passing
  • Build and lint clean

Stacked on #343

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 83.04348% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.79%. Comparing base (1f7bc7a) to head (980d41f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ode-parser/graph/callgraph/statement_extraction.go 83.04% 23 Missing and 16 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #344      +/-   ##
==========================================
+ Coverage   75.50%   75.79%   +0.29%     
==========================================
  Files          49       50       +1     
  Lines        5699     5929     +230     
==========================================
+ Hits         4303     4494     +191     
- Misses       1221     1244      +23     
- Partials      175      191      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shivasurya shivasurya self-assigned this Nov 4, 2025
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Nov 4, 2025
@shivasurya shivasurya marked this pull request as ready for review November 4, 2025 00:50
@safedep
Copy link

safedep bot commented Nov 4, 2025

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

Copy link
Owner Author

shivasurya commented Nov 4, 2025

Merge activity

  • Nov 4, 1:51 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 4, 1:52 AM UTC: Graphite rebased this pull request as part of a merge.
  • Nov 4, 1:53 AM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya changed the base branch from feat/intra-procedural-dataflow-pr1-data-structures to graphite-base/344 November 4, 2025 01:51
@shivasurya shivasurya changed the base branch from graphite-base/344 to main November 4, 2025 01:51
shivasurya and others added 2 commits November 4, 2025 01:52
… dataflow

Implements statement-level extraction from Python AST to support
intra-procedural dataflow analysis and taint propagation.

This is PR #2 of the intra-procedural dataflow feature implementation.

**Key Features:**
- Extract assignments, augmented assignments, calls, and returns
- Build def-use information for each statement
- Conservative identifier extraction for security analysis
- Handle Python AST node wrapping (expression_statement)
- Filter Python keywords and 'self' references
- Extract method names from chained calls (obj.a.b.method)

**Implementation Details:**
- `ExtractStatements`: Main entry point, iterates function body
- `extractAssignment`: Handles simple assignments (x = expr)
  - Stores RHS expression in CallTarget field
  - Skips tuple unpacking (requires multiple defs)
  - Skips attribute/subscript assignments (no local defs)
- `extractAugmentedAssignment`: Handles x += expr (def and use)
- `extractCall`: Extracts function/method calls
  - CallTarget contains method name (not full chain)
  - CallArgs contains literal argument values
  - Uses contains all identifiers (recursive extraction)
- `extractReturn`: Handles return statements
  - Stores expression in CallTarget
- `extractIdentifiers`: Recursive identifier extraction
  - Filters Python keywords and 'self'
  - Deduplicates results

**Test Coverage:**
- 20+ comprehensive tests covering all statement types
- 87.3% overall coverage
- Edge cases: empty functions, control flow skipped, nested calls
- Tests for keyword filtering, deduplication, self references

**Compliance:**
- All tests passing
- Build successful
- Linter clean (nolint comments for false-positive unconvert warnings)

Related to #340

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…erage

Adds 15+ additional tests to improve coverage from 87.3% to 87.7%.

**New Test Coverage:**
- Augmented assignment with attributes/subscripts
- Complex call target expressions (lambda calls)
- Nil node safety checks
- Line number tracking
- Nested keyword arguments
- Assignment from literals
- Return with multiple identifiers
- Edge cases for defensive coding

**Coverage Improvements:**
- extractIdentifiersFromArgs: 92.0% → 96.0%
- extractCallArgs: 91.3% → 95.7%
- extractIdentifiers: 88.9% → 94.4%
- ExtractStatements: 88.9% → 92.6%

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@shivasurya shivasurya force-pushed the feat/intra-procedural-dataflow-pr2-statement-extraction branch from 9f592e5 to 980d41f Compare November 4, 2025 01:52
@shivasurya shivasurya merged commit 29eb111 into main Nov 4, 2025
5 checks passed
@shivasurya shivasurya deleted the feat/intra-procedural-dataflow-pr2-statement-extraction branch November 4, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants