diff --git a/src/spellbind/str_values.py b/src/spellbind/str_values.py index 6f86ec1..1676062 100644 --- a/src/spellbind/str_values.py +++ b/src/spellbind/str_values.py @@ -50,7 +50,7 @@ def length(self) -> IntValue: def to_str(self) -> StrValue: return self - def format(self, **kwargs) -> StrValue: + def format(self, **kwargs: StrLike) -> StrValue: """Format this StrValue using the provided keyword arguments. Updates to self or any of the keyword arguments will cause the resulting StrValue to update accordingly. @@ -106,6 +106,13 @@ def derive_from_many(cls, transformer: Callable[[Iterable[str]], str], *values: is_associative=is_associative, ) + @classmethod + def str_of(cls, value: Any) -> StrValue: + if isinstance(value, Value): + return value.to_str() + else: + return StrConstant.of(str(value)) + def concatenate(*values: StrLike) -> StrValue: return StrValue.derive_from_many(_join_strs, *values, is_associative=True)