Python function definition formatter
def-form is a code formatting tool that focuses specifically on Python function definitions. It helps maintain consistent formatting of function signatures by automatically organizing arguments vertically when they exceed specified thresholds.
- Automatic argument formatting: Converts inline function arguments to vertical format based on configurable rules
- CI/CD integration: Provides both
formatandcheckcommands for use in development pipelines - Configuration file support: Uses
pyproject.tomlfor project-specific settings - Customizable thresholds: Control when arguments should be formatted vertically
pip install def-form- Format all Python files in a directory:
def-form format src/- Format a specific file:
def-form format my_module.py- Check if code follows formatting rules:
def-form check src/def-form format [OPTIONS] [PATH]
Options:
--max-def-length INTEGER Maximum length of function definition
--max-inline-args INTEGER Maximum number of inline arguments
--indent-size INTEGER indent size in spaces (default: 4)
--exclude TEXT Paths or files to exclude from checking/formatting
--show-skipped Show skipped files/directories
--config TEXT Path to pyproject.toml configuration file
Create a pyproject.toml file in your project root:
[tool.def-form]
max_def_length = 100
max_inline_args = 2
indent_size = 4
exclude = [
'.venv',
'migrations'
]- max_def_length: Maximum allowed characters in a single-line function definition
- max_inline_args: Maximum number of arguments allowed in inline format
- indent_size: Indent for arguments in spaces
- exclude: Files or directories you want to exclude