MCPcopy Index your code
hub / github.com/apache/tvm / _format_python_function

Method _format_python_function

python/tvm/relax/base_py_module.py:587–601  ·  view source on GitHub ↗

Format a Python function with proper indentation for TVMScript.

(self, _func_name: str, func_source: str, indent: int)

Source from the content-addressed store, hash-verified

585 return None
586
587 def _format_python_function(self, _func_name: str, func_source: str, indent: int) -> str:
588 """Format a Python function with proper indentation for TVMScript."""
589 lines = func_source.split("\n")
590 formatted_lines = []
591
592 for line in lines:
593 # Skip the function definition line if it's already properly indented
594 if line.strip().startswith("def ") or line.strip().startswith("@"):
595 # Keep decorators and function definition as is
596 formatted_lines.append(" " * indent + line.strip())
597 else:
598 # Add proper indentation for the function body
599 formatted_lines.append(" " * indent + line.strip())
600
601 return "\n".join(formatted_lines)
602
603 def show(self, style: str | None = None, black_format: bool | None = None, **kwargs) -> None:
604 """A sugar for print highlighted TVM script with Python function support.

Callers 1

Calls 3

splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected