From b7762b91765419a98850819327738d949f8811d5 Mon Sep 17 00:00:00 2001 From: Mix <32300164+mnixry@users.noreply.github.com> Date: Thu, 10 Feb 2022 13:17:11 +0800 Subject: [PATCH] :lock: :bug: Add initial value to vformat results list, fix #781 --- nonebot/internal/adapter/template.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/nonebot/internal/adapter/template.py b/nonebot/internal/adapter/template.py index 22d2aebb..e04830a8 100644 --- a/nonebot/internal/adapter/template.py +++ b/nonebot/internal/adapter/template.py @@ -104,7 +104,7 @@ class MessageTemplate(Formatter, Generic[TF]): if recursion_depth < 0: raise ValueError("Max string recursion exceeded") - results: List[Any] = [] + results: List[Any] = [self.factory()] for (literal_text, field_name, format_spec, conversion) in self.parse( format_string @@ -162,10 +162,7 @@ class MessageTemplate(Formatter, Generic[TF]): formatted_text = self.format_field(obj, str(format_control)) results.append(formatted_text) - return ( - self.factory(functools.reduce(self._add, results or [""])), - auto_arg_index, - ) + return functools.reduce(self._add, results), auto_arg_index def format_field(self, value: Any, format_spec: str) -> Any: formatter: Optional[FormatSpecFunc] = self.format_specs.get(format_spec)