MCPcopy Index your code
hub / github.com/python/mypy / apply_signature_hook

Method apply_signature_hook

mypy/checkexpr.py:1287–1317  ·  view source on GitHub ↗

Helper to apply a signature hook for either a function or method

(
        self,
        callee: FunctionLike,
        args: list[Expression],
        arg_kinds: list[ArgKind],
        arg_names: Sequence[str | None] | None,
        hook: Callable[[list[list[Expression]], CallableType], FunctionLike],
    )

Source from the content-addressed store, hash-verified

1285 )
1286
1287 def apply_signature_hook(
1288 self,
1289 callee: FunctionLike,
1290 args: list[Expression],
1291 arg_kinds: list[ArgKind],
1292 arg_names: Sequence[str | None] | None,
1293 hook: Callable[[list[list[Expression]], CallableType], FunctionLike],
1294 ) -> FunctionLike:
1295 """Helper to apply a signature hook for either a function or method"""
1296 if isinstance(callee, CallableType):
1297 num_formals = len(callee.arg_kinds)
1298 formal_to_actual = map_actuals_to_formals(
1299 arg_kinds,
1300 arg_names,
1301 callee.arg_kinds,
1302 callee.arg_names,
1303 lambda i: self.accept(args[i]),
1304 )
1305 formal_arg_exprs: list[list[Expression]] = [[] for _ in range(num_formals)]
1306 for formal, actuals in enumerate(formal_to_actual):
1307 for actual in actuals:
1308 formal_arg_exprs[formal].append(args[actual])
1309 return hook(formal_arg_exprs, callee)
1310 else:
1311 assert isinstance(callee, Overloaded)
1312 items = []
1313 for item in callee.items:
1314 adjusted = self.apply_signature_hook(item, args, arg_kinds, arg_names, hook)
1315 assert isinstance(adjusted, CallableType)
1316 items.append(adjusted)
1317 return Overloaded(items)
1318
1319 def apply_function_signature_hook(
1320 self,

Calls 8

acceptMethod · 0.95
map_actuals_to_formalsFunction · 0.90
OverloadedClass · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
rangeClass · 0.85
enumerateFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected