mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +00:00
♻️ rename message formatter into template
This commit is contained in:
@ -22,5 +22,5 @@ except Exception:
|
||||
|
||||
from ._bot import Bot
|
||||
from ._event import Event
|
||||
from ._formatter import MessageFormatter
|
||||
from ._template import MessageTemplate
|
||||
from ._message import Message, MessageSegment
|
||||
|
@ -4,7 +4,7 @@ from dataclasses import dataclass, field, asdict
|
||||
from typing import (Any, List, Dict, Type, Union, TypeVar, Mapping, Generic,
|
||||
Iterable)
|
||||
|
||||
from ._formatter import MessageFormatter
|
||||
from ._template import MessageTemplate
|
||||
|
||||
T = TypeVar("T")
|
||||
TMS = TypeVar("TMS", covariant=True)
|
||||
@ -103,7 +103,7 @@ class Message(List[TMS], abc.ABC):
|
||||
self.extend(self._construct(message))
|
||||
|
||||
@classmethod
|
||||
def template(cls: Type[TM], format_string: str) -> MessageFormatter[TM]:
|
||||
def template(cls: Type[TM], format_string: str) -> MessageTemplate[TM]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
@ -126,7 +126,7 @@ class Message(List[TMS], abc.ABC):
|
||||
|
||||
- ``MessageFormatter[TM]``: 消息格式化器
|
||||
"""
|
||||
return MessageFormatter(cls, format_string)
|
||||
return MessageTemplate(cls, format_string)
|
||||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
|
@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
||||
TM = TypeVar("TM", bound="Message")
|
||||
|
||||
|
||||
class MessageFormatter(Formatter, Generic[TM]):
|
||||
class MessageTemplate(Formatter, Generic[TM]):
|
||||
"""消息模板格式化实现类"""
|
||||
|
||||
def __init__(self, factory: Type[TM], template: str) -> None:
|
||||
@ -105,4 +105,5 @@ class MessageFormatter(Formatter, Generic[TM]):
|
||||
[""])), auto_arg_index
|
||||
|
||||
def format_field(self, value: Any, format_spec: str) -> Any:
|
||||
return super().format_field(value, format_spec) if format_spec else value
|
||||
return super().format_field(value,
|
||||
format_spec) if format_spec else value
|
Reference in New Issue
Block a user