fix(python/sast): Support default parameter type inference - #498
Merged
Merged
Conversation
…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 ✓
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
The typeEngine parameter is kept for strategy interface consistency and is used in the recursive call for boolean operators.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes type inference for constructor parameters with default values.
Changes
typed_default_parameterAST nodesTesting