Skip to content

bagof.converters.strings

Converters for string types.

Classes

ToString

ToString(hint: Any = UNSET, compose: bool = False)

Bases: Converter[STR, Any]

Converter for str.

Example

>>> from bagof.converters import get_converter
>>> get_converter(str)(b"hello")
'hello'

Methods:

like
like(__reentrant: tuple = ()) -> Any

Accept strings and bytes as input.

__call__
__call__(value: Any) -> STR

Convert the value to a string.

ToRegexMatch

ToRegexMatch(pattern: str | Pattern, hint: Any = UNSET)

Bases: ToString[STR]

Converter for strings that must match a regex pattern.

Parameters:

Name Type Description Default
pattern str | Pattern

The regex pattern to match against.

required
hint Any

The type hint to convert to.

UNSET

Methods:

__call__
__call__(value: Any) -> STR

Convert the value to a string and check it matches the pattern.