Exceptions

PatternParseMismatch

exception formatparse.PatternParseMismatch(*args, **kwargs)

Stub for PatternParseMismatch (extension not built).

__init__(*args, **kwargs)

Accept construction like the real Rust-backed type (docs build stub).

ValidationError

exception formatparse.ValidationError(message, *, field=None)[source]

Raised when a post-parse validator rejects a field.

Subclass of ValueError for compatibility with except ValueError. Validators should raise this (or let apply_validators() wrap other exceptions) so callers can inspect field.

See GitHub issue #10.

Parameters:
  • message (str) – Human-readable reason the value was rejected.

  • field (Union[str, int, None]) – Parsed field identifier — str for a named field or int for a positional fixed index (same convention as validators keys).

__init__(message, *, field=None)[source]

ValidationWarning

exception formatparse.ValidationWarning[source]

Issued when validation_mode='lenient' and a validator or hook fails.

MultipleValidationErrors

exception formatparse.MultipleValidationErrors(errors)[source]

Raised when validation_mode='collect' and at least one validator fails.

Not used for validation_mode='lenient' (failures are reported via ValidationWarning instead).

For apply_validators(), errors lists each ValidationError in key order (all int keys ascending, then str keys alphabetically). For ValidationPipeline.apply() in collect mode, field failures are listed first in that same order, followed by hook failures in hook registration order.

__init__(errors)[source]

RepeatedNameError

exception formatparse.RepeatedNameError[source]

Exception raised when a repeated field name has mismatched types.

This exception is raised when a format pattern contains the same field name multiple times with different type specifications (e.g., "{age:d}" and "{age:f}" in the same pattern).

Raises:

RepeatedNameError – When a repeated field name has mismatched types

Example:

>>> from formatparse import compile, RepeatedNameError
>>> try:
...     compile("{age:d} years and {age:f} months")
... except RepeatedNameError as e:
...     print(f"Error: {e}")