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

Function isOverloadStub

src/resolution/python-overloads.ts:92–110  ·  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

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

Callers 1

implementationOfFunction · 0.85

Calls 2

hasMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected