simplebench.reporters.validators.validators module🔗

Validators for reporters stuff.

simplebench.reporters.validators.validators.resolve_type_hints(
callback: Callable,
) dict[str, type][source]🔗

Resolve the type hints for a callback function.

Parameters:

callback – The callback function to resolve type hints for.

Returns:

A dictionary mapping parameter names to their resolved types.

Raises:

SimpleBenchTypeError – If the type hints cannot be resolved.

simplebench.reporters.validators.validators.validate_call_parameter(
call: Callable,
expected_type: type | Any,
param_name: str,
) None[source]🔗

Validate a parameter of the callback function.

The parameter must exist, be of the expected type, and be a keyword-only parameter.

Parameters:
  • call – The callback function to validate.

  • expected_type – The expected type of the parameter.

  • param_name – The name of the parameter to validate.

Raises:

SimpleBenchTypeError – If the parameter is invalid.

simplebench.reporters.validators.validators.validate_report_renderer(
renderer: ReportRenderer,
) ReportRenderer[source]🔗

Validate the report renderer method.

Verifies the renderer method has the correct signature. This is functionally equivalent to the ReportRenderer protocol.

A renderer function must accept the following three keyword-only parameters:

  • case: Case

  • section: Section

  • options: ReporterOptions

Parameters:

renderer – The renderer function to validate.

Returns:

The validated renderer function.

Raises:

SimpleBenchTypeError – If the renderer is invalid.

simplebench.reporters.validators.validators.validate_reporter_callback(
callback: Any,
) ReporterCallback[source]🔗
simplebench.reporters.validators.validators.validate_reporter_callback(
callback: Any,
*,
allow_none: bool,
) ReporterCallback | None

Validate the reporter callback function.

Verifies the callback function has the correct signature.

If called without an allow_none parameter, the returned value will be guaranteed to conform to the ReporterCallback protocol and type checkers will automatically type-narrow it.

If called with an allow_none=True parameter, the validator will accept either a ReporterCallback conformant method or None as valid.

If an explicit allow_none parameter is passed, regardless of whether allow_none=True or allow_none=False, the return type determined by static type checkers will be ReporterCallback | None.

A callback function must accept the following four keyword-only parameters:

  • case: Case

  • section: Section

  • output_format: Format

  • output: Any

Parameters:
  • callback – The callback function to validate.

  • allow_none – Whether to allow None as a valid value for the callback. Defaults to False.

Returns:

The validated callback function or None.

Raises:

SimpleBenchTypeError – If the callback is invalid.