MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scanPythonGetattr

Function scanPythonGetattr

src/mcp/dynamic-boundaries.ts:327–371  ·  view source on GitHub ↗
(stripped: string, original: string, fileStartLine: number, out: BoundaryMatch[], seen: Map<string, BoundaryMatch>)

Source from the content-addressed store, hash-verified

325const MAX_GETATTR_ARGS = 300;
326
327function scanPythonGetattr(stripped: string, original: string, fileStartLine: number, out: BoundaryMatch[], seen: Map<string, BoundaryMatch>): void {
328 GETATTR_RE.lastIndex = 0;
329 let m: RegExpExecArray | null;
330 while ((m = GETATTR_RE.exec(stripped)) !== null && out.length < MAX_MATCHES_PER_BODY) {
331 const open = m.index + m[0].length - 1;
332 const close = matchBalancedParen(stripped, open);
333 if (close === -1) continue;
334
335 let form: string | undefined;
336 let label = '';
337 // Immediate call: getattr(...)(
338 const after = stripped.slice(close + 1, close + 8);
339 if (/^\s*\(/.test(after)) {
340 form = 'getattr-call';
341 label = 'getattr dispatch';
342 } else {
343 // Assigned form: look back for `name =` and forward for `name(`.
344 const lineStart = stripped.lastIndexOf('\n', m.index) + 1;
345 const before = stripped.slice(lineStart, m.index);
346 const assign = before.match(/(\w+)\s*=\s*$/);
347 if (assign && new RegExp(`\\b${assign[1]}\\s*\\(`).test(stripped.slice(close + 1))) {
348 form = 'getattr-assign';
349 label = 'getattr dispatch (assigned, called later)';
350 }
351 }
352 if (!form) continue;
353
354 const key = singleStringLiteral(original.slice(open + 1, close));
355 const dedupeKey = `${form}|${key ?? ''}`;
356 const prior = seen.get(dedupeKey);
357 if (prior) {
358 prior.moreSites = (prior.moreSites ?? 0) + 1;
359 continue;
360 }
361 const match: BoundaryMatch = {
362 form,
363 label,
364 snippet: snippetAround(original, m.index),
365 line: fileStartLine + countNewlines(original, m.index),
366 ...(key ? { key } : {}),
367 };
368 seen.set(dedupeKey, match);
369 out.push(match);
370 }
371}
372
373/** Index of the `)` balancing `text[open]`, or -1 (cap: MAX_GETATTR_ARGS chars). */
374function matchBalancedParen(text: string, open: number): number {

Callers 1

scanDynamicDispatchFunction · 0.85

Calls 7

matchBalancedParenFunction · 0.85
singleStringLiteralFunction · 0.85
snippetAroundFunction · 0.85
countNewlinesFunction · 0.85
execMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected