-
Notifications
You must be signed in to change notification settings - Fork 10
feat(callgraph): Python Type Inference for Improved Call Resolution #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Add foundational data structures for type inference: - TypeInfo: tracks type FQN, confidence, and source - VariableBinding: tracks variable types within scopes - FunctionScope: maintains type environment per function - TypeInferenceEngine: coordinates type inference across codebase Tests: 100% coverage with 13 test cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add comprehensive builtin type registry for Python types: - BuiltinRegistry with all Python builtin types (str, list, dict, set, tuple, int, float, bool, bytes) - Method definitions with return types for each builtin - InferLiteralType for automatic type inference from literals - Support for numeric literals (int, float, scientific notation, hex, octal, binary) - Support for collection literals (list, dict, set, tuple) - Support for string and bytes literals Integrate builtin registry with TypeInferenceEngine Tests: 100% coverage with 16 test cases covering all types and methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add AST traversal to extract variable assignments for type inference: - ExtractVariableAssignments traverses Python AST to find assignments - processAssignment extracts type from RHS expression - inferTypeFromExpression handles literal type inference - Supports string, numeric, collection, bool, and None literals - Tracks variable bindings per function scope - Records source locations for each assignment Integration with type inference engine: - Populates function scopes with variable bindings - Handles nested function scopes - Supports variable reassignment (last wins) Tests: 83-93% coverage with 11 test cases covering all literal types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Integrate type inference engine with call graph resolution: - Initialize TypeInferenceEngine in BuildCallGraph - Extract variable assignments during graph building - Use type inference to resolve variable.method() calls - Resolve builtin method calls (str.upper, list.append, dict.keys, etc.) - Fallback to legacy resolution for backward compatibility Type-aware resolution logic: - Check variable bindings in function scope - Resolve builtin methods via BuiltinRegistry - Support user-defined type methods - Maintains 100% backward compatibility with existing tests Integration tests: 5 test cases covering string, list, dict methods and edge cases - TestTypeInference_StringMethods: data.upper() resolution - TestTypeInference_ListMethods: numbers.append(), numbers.count() - TestTypeInference_DictMethods: config.keys(), config.values() - TestTypeInference_MultipleVariables: mixed type resolution - TestTypeInference_WithoutTypeInfo: graceful fallback Backward compatibility: - resolveCallTargetLegacy for tests without type engine - All existing tests pass unchanged 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
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 #334 +/- ##
==========================================
+ Coverage 73.87% 76.03% +2.15%
==========================================
Files 35 38 +3
Lines 3560 4102 +542
==========================================
+ Hits 2630 3119 +489
- Misses 841 877 +36
- Partials 89 106 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Convert if-else chain to switch statement in isNumericLiteral - Add period to TODO comment - Add nolint directives for disabled test function 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
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
Implements Phase 1 of type inference to dramatically improve Python callsite resolution rates. This PR adds the ability to track variable types through literal assignments and resolve method calls on Python builtin types.
Changes
type_inference.go)builtin_registry.go)variable_extraction.go)builder.goto use type inference forvariable.method()patternsPerformance Impact
Test Project Results
Real-World Project (label-studio)
Technical Details
Testing
All existing tests pass. New test coverage:
type_inference_test.go: 13 test cases (100% coverage)builtin_registry_test.go: 16 test cases (100% coverage)variable_extraction_test.go: 11 test cases (83-93% coverage)integration_type_inference_test.go: 5 integration testsFuture Work (Phase 2)