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 = ", ",
)
| 122 | |
| 123 | |
| 124 | def 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 | |
| 147 | def Method(name: str, args: List[str], body: List[str], **kwargs: Any) -> Callable: |
no test coverage detected