Skip to main content

Formatter

This class provides functionality for parsing and formatting strings based on specific format specifiers. It processes input strings by mapping identified placeholders to internal methods while enforcing type-specific constraints, such as preventing time-related specifiers on date objects.

Attributes

AttributeTypeDescription
dataobjectThe underlying object, such as a date or time instance, used to resolve format specifiers during the string construction process.

Methods


format()

@classmethod
def format(
formatstr: string
) - > string

Parses a format string and replaces placeholders with corresponding attribute values from the instance. This method validates that date objects do not use time-related specifiers and handles escaped characters within the input string.

Parameters

NameTypeDescription
formatstrstringThe template string containing format specifiers and escaped characters to be processed.

Returns

TypeDescription
stringThe fully interpolated string with all format specifiers replaced by their evaluated values.