ballet.util.code module¶
-
ballet.util.code.blacken_code(code)[source]¶ Format code content using Black
- Parameters
code (
str) – code as string- Return type
str
-
ballet.util.code.get_source(f)[source]¶ Extract the source code from a given function.
Recursively extracts the source code for all local functions called by given function. The resulting source code is encoded in utf-8.
Known limitation: Cannot use on function defined interactively in normal Python terminal. (Functions defined interactively in IPython are okay.)
- Parameters
f (
function) – function- Return type
str- Returns
extracted source code
- Raises
NotImplementedError – if the function was defined interactively