Exceptions
PatternParseMismatch
ValidationError
- exception formatparse.ValidationError(message, *, field=None)[source]
Raised when a post-parse validator rejects a field.
Subclass of
ValueErrorfor compatibility withexcept ValueError. Validators should raise this (or letapply_validators()wrap other exceptions) so callers can inspectfield.See GitHub issue #10.
- Parameters:
ValidationWarning
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 viaValidationWarninginstead).For
apply_validators(),errorslists eachValidationErrorin key order (allintkeys ascending, thenstrkeys alphabetically). ForValidationPipeline.apply()incollectmode, field failures are listed first in that same order, followed by hook failures in hook registration order.
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}")