Skip to content

fix(python/sast): Support default parameter type inference - #498

Merged
shivasurya merged 3 commits into
mainfrom
shiva/p0-conditional-pattern-fix
Jan 31, 2026
Merged

shivasurya merged 3 commits into
mainfrom
shiva/p0-conditional-pattern-fix

Conversation

@shivasurya

Copy link
Copy Markdown
Owner

Summary

Fixes type inference for constructor parameters with default values.

Changes

  • Handle typed_default_parameter AST nodes
  • Strip type hint wrappers (Optional, Union, |)
  • Support boolean operator patterns

Testing

  • ✅ All tests passing (98.16% coverage)
  • ✅ Verified on label-studio codebase
  • ✅ 93.75% call resolution rate

shivasurya and others added 2 commits January 30, 2026 18:46
…erence

Fixed attribute extraction for Python conditional assignment pattern:
  self.controller = controller or Controller()

Changes:
1. Handle typed_default_parameter nodes (params with type annotation AND default value)
2. Extract identifier from Child(0) for typed_default_parameter (not via field name)
3. Strip type hint wrappers (Optional[], Union[], |) before placeholder resolution
4. Handle boolean operators in class instantiation strategy
5. Reorder strategies: constructor params (0.95) before class instantiation (0.9)

The fix enables type inference for:
- Typed: def __init__(self, x: Optional[Controller] = None)
- Untyped: def __init__(self, x=None) with x or Controller()

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Replaced specific controller/service names from analysis examples with
generic class names to keep the codebase implementation-agnostic.

Changes:
- ManagedSSOController → Controller
- UserController → Controller
- SSOController → Service
- InvitationController → Manager
- TwoFactorMFAController → Processor

Updated files:
- graph/callgraph/extraction/attributes.go
- graph/callgraph/extraction/attributes_coverage_test.go
- graph/callgraph/resolution/attribute.go
- graph/callgraph/resolution/inference_test.go
- graph/callgraph/resolution/attribute_test.go

All tests passing ✓
@shivasurya shivasurya added the enhancement New feature or request label Jan 31, 2026
@shivasurya shivasurya self-assigned this Jan 31, 2026
@safedep

safedep Bot commented Jan 31, 2026 •

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jan 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.34109% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.18%. Comparing base (8bf32e1) to head (78fc3ed).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...st-engine/graph/callgraph/extraction/attributes.go 67.39% 22 Missing and 8 partials ⚠️
...ast-engine/graph/callgraph/extraction/variables.go 56.75% 14 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #498      +/-   ##
==========================================
- Coverage   81.26%   81.18%   -0.08%     
==========================================
  Files         113      113              
  Lines       13129    13249     +120     
==========================================
+ Hits        10669    10756      +87     
- Misses       2066     2091      +25     
- Partials      394      402       +8     

☔ 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.

The typeEngine parameter is kept for strategy interface consistency
and is used in the recursive call for boolean operators.
@shivasurya
shivasurya merged commit 50b21c9 into main Jan 31, 2026
4 of 6 checks passed
@shivasurya
shivasurya deleted the shiva/p0-conditional-pattern-fix branch January 31, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant