Commit 7c03b52
fix(python/sast): Fix instance method return type propagation for OOP patterns (#484)
* docs(claude): Update CLAUDE.md to remove deprecated query command references
- Remove outdated 'pathfinder query' CLI command (removed pre-v1.0.0)
- Replace Query Language section with Python DSL Rules documentation
- Update architecture diagram to reflect current MCP server + call graph design
- Update Core Packages to include callgraph/resolution modules
- Remove pagination references (feature no longer exists)
- Update test examples to reference actual test files
- Add current CLI commands: serve, scan, ci, resolution-report, diagnose
* fix(python/sast): Fix instance method return type propagation for OOP patterns
**Problem:**
Instance method calls like obj.method() were failing with 80% of Python OOP code
being unresolved. Two critical bugs were found:
1. UpdateVariableBindingsWithFunctionReturns() couldn't distinguish between
instance.method() and module.function() patterns
2. Return type extraction didn't track class context, so method return types
were indexed without class-qualified FQNs
**Example of failing code:**
```python
manager = UserManager()
user = manager.create_user("bob") # Creates placeholder "call:manager.create_user"
user.is_valid() # FAILED - couldn't resolve
```
**Root Causes:**
Bug 1 (inference.go:136-139):
- When funcName contained dots (e.g., "manager.create_user"), code assumed it was
a module path and used it as-is
- But "manager.create_user" is receiver.method, NOT module.function
- Should have checked if "manager" is a variable, extracted its type, and built
class-qualified FQN "main.UserManager.create_user"
Bug 2 (return_type.go:56-68):
- Return type extraction only tracked function_definition nodes, not class_definition
- Methods inside classes got FQNs like "main.create_user" instead of
"main.UserManager.create_user"
- Return type lookup failed because keys didn't match
**Fixes:**
1. Enhanced UpdateVariableBindingsWithFunctionReturns() to:
- Split dotted funcNames into receiver + method
- Check if receiver is a variable in current scope
- If yes, use receiver's type to build class-qualified FQN
- If no, assume it's a module path (backward compatible)
2. Enhanced return type extraction to:
- Track class_definition nodes and build class context
- Build class-qualified FQNs for methods (module.ClassName.methodName)
- Added extractClassNameFromNode() helper function
**Impact:**
- Resolution rate improved from 80% → 93.3% (+13.3%)
- Type inference usage increased from 33.3% → 42.9% of resolved calls
- Instance method calls now work: obj.method() → Class.method ✅
- Chained calls now work: user.get_profile().update() ✅
- Module functions still work: logging.getLogger() ✅
**Test Coverage:**
Added 5 comprehensive test functions covering:
- Basic instance method calls (receiver.method)
- Chained instance methods (multi-pass resolution)
- Instance.method vs module.function disambiguation
- Unresolved receiver type handling (edge case)
- Nested method calls (a.b.c.method pattern)
All quality gates pass:
✅ gradle testGo - all tests pass
✅ gradle buildGo - clean build
✅ gradle lintGo - no lint errors
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* test(python/sast): Add comprehensive tests for class context tracking in return type extraction
- Add 6 new test functions covering class-qualified FQN generation
- Test class methods, nested classes, and extractClassNameFromNode helper
- Achieves 100% coverage for new code in return_type.go (lines 60-71, 426-440)
- All tests pass: gradle testGo, lintGo clean
Tests added:
- TestExtractReturnTypes_ClassMethods: Methods get class-qualified FQNs
- TestExtractReturnTypes_NestedClasses: Nested class methods work correctly
- TestExtractReturnTypes_ModuleLevelAndClassMethod: Distinguish module vs class functions
- TestExtractClassNameFromNode: Direct test of helper function
- TestExtractReturnTypes_EmptyClass: Edge case with no methods
- TestExtractReturnTypes_ClassWithMultipleMethods: Multiple methods in same class
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent e0efe83 commit 7c03b52
File tree
5 files changed
+643
-111
lines changed- sast-engine/graph/callgraph/resolution
5 files changed
+643
-111
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | | - | |
37 | | - | |
| 40 | + | |
| 41 | + | |
38 | 42 | | |
39 | | - | |
40 | | - | |
| 43 | + | |
| 44 | + | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
45 | | - | |
| 49 | + | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
50 | | - | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
54 | 61 | | |
55 | | - | |
| 62 | + | |
56 | 63 | | |
57 | | - | |
| 64 | + | |
58 | 65 | | |
59 | | - | |
| 66 | + | |
60 | 67 | | |
61 | | - | |
| 68 | + | |
62 | 69 | | |
63 | | - | |
| 70 | + | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
69 | | - | |
| 76 | + | |
70 | 77 | | |
71 | 78 | | |
72 | 79 | | |
73 | | - | |
74 | 80 | | |
75 | 81 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
81 | | - | |
82 | | - | |
| 91 | + | |
83 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
84 | 96 | | |
85 | 97 | | |
86 | 98 | | |
| |||
222 | 234 | | |
223 | 235 | | |
224 | 236 | | |
225 | | - | |
226 | | - | |
227 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
228 | 264 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | 265 | | |
255 | | - | |
256 | | - | |
257 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
258 | 273 | | |
259 | | - | |
260 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
261 | 278 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
| 279 | + | |
| 280 | + | |
282 | 281 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 282 | + | |
| 283 | + | |
288 | 284 | | |
289 | 285 | | |
290 | | - | |
291 | | - | |
292 | 286 | | |
293 | 287 | | |
294 | 288 | | |
| |||
312 | 306 | | |
313 | 307 | | |
314 | 308 | | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
319 | 314 | | |
320 | 315 | | |
321 | 316 | | |
| |||
377 | 372 | | |
378 | 373 | | |
379 | 374 | | |
380 | | - | |
381 | | - | |
| 375 | + | |
| 376 | + | |
382 | 377 | | |
383 | | - | |
384 | | - | |
385 | | - | |
| 378 | + | |
| 379 | + | |
386 | 380 | | |
387 | 381 | | |
388 | 382 | | |
| |||
419 | 413 | | |
420 | 414 | | |
421 | 415 | | |
422 | | - | |
| 416 | + | |
423 | 417 | | |
424 | 418 | | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
429 | 423 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
434 | 429 | | |
435 | 430 | | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | | - | |
138 | | - | |
139 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
140 | 160 | | |
141 | 161 | | |
142 | 162 | | |
| |||
0 commit comments