Implementation:Mlflow Mlflow Check Function Signatures
| Knowledge Sources | |
|---|---|
| Domains | CI, CodeQuality |
| Last Updated | 2026-02-13 20:00 GMT |
Overview
Detects backward-incompatible changes to public Python function signatures in pull requests by comparing AST-parsed signatures against the base branch.
Description
This script uses Python's ast module to parse function signatures from changed files and compare them against the base branch version. It enforces several backward-compatibility rules:
For positional and positional-only parameters:
- Parameters cannot be reordered, renamed, or removed.
- Adding required positional parameters is a breaking change.
- Adding optional positional parameters is allowed only at the end.
- Making an optional parameter required is a breaking change.
For keyword-only parameters (order-agnostic):
- Parameters cannot be renamed or removed.
- Making an optional parameter required is a breaking change.
- Adding a required keyword-only parameter is a breaking change; adding an optional one is allowed.
The script filters to only check public modules under mlflow/, skipping private modules (those starting with underscore) and private functions. It produces GitHub Actions-compatible warning annotations when running in CI, or plain text output for local use.
Key dataclasses include Parameter (representing a single function parameter with position, required status, and kind), Signature (grouping positional and keyword-only parameters), and Error (formatting violation output).
Usage
Run this script in CI to detect breaking API changes before merging pull requests. It can also be run locally to check for signature compatibility against a base branch.
Code Reference
Source Location
- Repository: Mlflow_Mlflow
- File: dev/check_function_signatures.py
- Lines: 1-382
Signature
@dataclass
class Error:
file_path: Path
line: int
column: int
lines: list[str]
def format(self, github: bool = False) -> str: ...
@dataclass
class Parameter:
name: str
position: int | None
is_required: bool
is_positional_only: bool
is_keyword_only: bool
lineno: int
col_offset: int
@dataclass
class Signature:
positional: list[Parameter]
keyword_only: list[Parameter]
has_var_positional: bool
has_var_keyword: bool
def parse_signature(args: ast.arguments) -> Signature: ...
def check_signature_compatibility(
old_fn: ast.FunctionDef | ast.AsyncFunctionDef,
new_fn: ast.FunctionDef | ast.AsyncFunctionDef,
) -> list[ParameterError]: ...
def compare_signatures(base_branch: str = "master") -> list[Error]: ...
def main() -> None: ...
Import
# Run from repository root
python dev/check_function_signatures.py
# Specify a custom base branch
python dev/check_function_signatures.py --base-branch main
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --base-branch | str | No | Base branch to compare against (default: GITHUB_BASE_REF env var or "master") |
Outputs
| Name | Type | Description |
|---|---|---|
| Warnings | stdout | Breaking change warnings in GitHub Actions annotation format or plain text format |
Usage Examples
Basic Usage
# Run locally against master branch
python dev/check_function_signatures.py
# Run against a specific base branch
python dev/check_function_signatures.py --base-branch release/2.0
# In GitHub Actions CI (uses GITHUB_BASE_REF automatically)
python dev/check_function_signatures.py