MCPcopy
hub / github.com/faust-streaming/faust / build_closure_source

Function build_closure_source

faust/utils/codegen.py:52–86  ·  view source on GitHub ↗
(
    name: str,
    args: List[str],
    body: List[str],
    *,
    outer_name: str = "__outer__",
    outer_args: List[str] = None,
    closures: Dict[str, str],
    return_type: Any = MISSING,
    indentlevel: int = 0,
    indentspaces: int = 4,
    argsep: str = ", ",
)

Source from the content-addressed store, hash-verified

50
51
52def build_closure_source(
53 name: str,
54 args: List[str],
55 body: List[str],
56 *,
57 outer_name: str = "__outer__",
58 outer_args: List[str] = None,
59 closures: Dict[str, str],
60 return_type: Any = MISSING,
61 indentlevel: int = 0,
62 indentspaces: int = 4,
63 argsep: str = ", ",
64) -> str:
65 inner_source = build_function_source(
66 name,
67 args,
68 body,
69 return_type=return_type,
70 indentlevel=indentlevel,
71 indentspaces=indentspaces,
72 argsep=argsep,
73 )
74 closure_vars = [
75 f"{local_name} = {global_name}" for local_name, global_name in closures.items()
76 ]
77 outer_source = build_function_source(
78 name=outer_name,
79 args=outer_args or [],
80 body=closure_vars + inner_source.split("\n") + [f"return {name}"],
81 return_type=MISSING,
82 indentlevel=indentlevel,
83 indentspaces=indentspaces,
84 argsep=argsep,
85 )
86 return outer_source
87
88
89def build_closure(

Callers

nothing calls this directly

Calls 2

build_function_sourceFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected