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

Function isOverloadStub

src/resolution/python-overloads.ts:91–109  ·  view source on GitHub ↗

Whether the decorators above a `def` hold typing's `overload`.

(def: Node, lines: string[], overload: { bare: Set<string>; modules: Set<string> })

Source from the content-addressed store, hash-verified

89
90/** Whether the decorators above a `def` hold typing's `overload`. */
91function isOverloadStub(def: Node, lines: string[], overload: { bare: Set<string>; modules: Set<string> }): boolean {
92 // Upward from the line above the `def`: decorators, and inside a decorator's
93 // parentheses the lines of its arguments. A `)` read going up opens such a
94 // span, which its `(` closes.
95 let open = 0;
96 for (let i = def.startLine - 2; i >= 0 && i >= def.startLine - 1 - DECORATOR_REACH; i--) {
97 const text = (lines[i] ?? '').trim();
98 open += (text.match(/\)/g)?.length ?? 0) - (text.match(/\(/g)?.length ?? 0);
99 if (open > 0) continue;
100 open = 0;
101 if (text === '' || text.startsWith('#')) continue;
102 if (!text.startsWith('@')) return false;
103 const m = /^@\s*((?:\w+\s*\.\s*)*)(\w+)/.exec(text);
104 if (!m) continue;
105 const via = m[1]!.replace(/\s/g, '').replace(/\.$/, '');
106 if (via ? m[2] === 'overload' && overload.modules.has(via) : overload.bare.has(m[2]!)) return true;
107 }
108 return false;
109}

Callers 1

implementationOfFunction · 0.85

Calls 2

hasMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected