INNER CODE UNIT · Python
Formatter
volfpeter/htmy · htmy/core.py:222
class Formatter(ContextAware):
"""
The default, context-aware property name and value formatter.
The formatter supports both primitive and (many) complex values, such as lists,
dictionaries, tuples, and sets. Complex values are JSON-serialized by default.
Important: the default implementation looks up the formatter for a given value by checking
its type, but it doesn't do this check with the base classes of the encountered type. For
example the formatter will know how to format `datetime` object, but it won't know how to
format a `MyCustomDatetime(datetime)` instance.
One reason for this is efficiency: always checking the base classes of every single value is a
lot of unnecessary calculation. The other reason is customizability: this way you could use
subclassing for formatter selection, e.g. with `LocaleDatetime(datetime)`-like classes.
Property name and value formatters may raise a `SkipProperty` error if a property should be skipped.