MCPcopy
hub / github.com/nonebot/nonebot2 / _format

Method _format

nonebot/internal/adapter/template.py:88–111  ·  view source on GitHub ↗
(self, args: Sequence[Any], kwargs: Mapping[str, Any])

Source from the content-addressed store, hash-verified

86 return self._format([], mapping)
87
88 def _format(self, args: Sequence[Any], kwargs: Mapping[str, Any]) -> TF:
89 full_message = self.factory()
90 used_args, arg_index = set(), 0
91
92 if isinstance(self.template, str):
93 msg, arg_index = self._vformat(
94 self.template, args, kwargs, used_args, arg_index
95 )
96 full_message += msg
97 elif isinstance(self.template, self.factory):
98 template = cast("Message[MessageSegment]", self.template)
99 for seg in template:
100 if not seg.is_text():
101 full_message += seg
102 else:
103 msg, arg_index = self._vformat(
104 str(seg), args, kwargs, used_args, arg_index
105 )
106 full_message += msg
107 else:
108 raise TypeError("template must be a string or instance of Message!")
109
110 self.check_unused_args(used_args, args, kwargs)
111 return cast(TF, full_message)
112
113 def vformat( # pyright: ignore[reportIncompatibleMethodOverride]
114 self,

Callers 2

formatMethod · 0.95
format_mapMethod · 0.95

Calls 2

_vformatMethod · 0.95
is_textMethod · 0.45

Tested by

no test coverage detected