♻️ rename message formatter into template

This commit is contained in:
yanyongyu
2021-09-11 19:48:46 +08:00
parent 59f567004f
commit 44d13acc81
4 changed files with 10 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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