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

Function build_function_source

faust/utils/codegen.py:124–144  ·  view source on GitHub ↗

Generate function source code from args and body.

(
    name: str,
    args: List[str],
    body: List[str],
    *,
    return_type: Any = MISSING,
    indentlevel: int = 0,
    indentspaces: int = 4,
    argsep: str = ", ",
)

Source from the content-addressed store, hash-verified

122
123
124def build_function_source(
125 name: str,
126 args: List[str],
127 body: List[str],
128 *,
129 return_type: Any = MISSING,
130 indentlevel: int = 0,
131 indentspaces: int = 4,
132 argsep: str = ", ",
133) -> str:
134 """Generate function source code from args and body."""
135 indent = " " * indentspaces
136 curindent = indent * indentlevel
137 nextindent = indent * (indentlevel + 1)
138 return_annotation = ""
139 if return_type is not MISSING:
140 return_annotation = "->_return_type"
141 bodys = "\n".join(f"{nextindent}{b}" for b in body)
142 return (
143 f"{curindent}def {name}({argsep.join(args)}){return_annotation}:\n" f"{bodys}"
144 )
145
146
147def Method(name: str, args: List[str], body: List[str], **kwargs: Any) -> Callable:

Callers 2

FunctionFunction · 0.85
build_closure_sourceFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected