🐛 修复当消息与不支持的类型相加时抛出的异常类型错误 (#1166)

This commit is contained in:
Mix 2022-08-22 14:39:00 +08:00 committed by GitHub
parent be5ac88a18
commit 92ff1df419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -186,7 +186,7 @@ class Message(List[TMS], abc.ABC):
elif isinstance(other, Iterable):
self.extend(other)
else:
raise ValueError(f"Unsupported type: {type(other)}") # pragma: no cover
raise TypeError(f"Unsupported type {type(other)!r}")
return self
@overload

View File

@ -11,11 +11,11 @@ def test_template_basis():
def test_template_message():
Message = make_fake_message()
template = Message.template("{a:custom}{b:text}{c:image}")
template = Message.template("{a:custom}{b:text}{c:image}/{d}")
@template.add_format_spec
def custom(input: str) -> str:
return input + "-custom!"
return f"{input}-custom!"
try:
template.add_format_spec(custom)
@ -24,12 +24,17 @@ def test_template_message():
else:
raise AssertionError("Should raise ValueError")
format_args = {"a": "custom", "b": "text", "c": "https://example.com/test"}
format_args = {
"a": "custom",
"b": "text",
"c": "https://example.com/test",
"d": 114,
}
formatted = template.format(**format_args)
assert template.format_map(format_args) == formatted
assert formatted.extract_plain_text() == "custom-custom!text"
assert str(formatted) == "custom-custom!text[fake:image]"
assert formatted.extract_plain_text() == "custom-custom!text/114"
assert str(formatted) == "custom-custom!text[fake:image]/114"
def test_rich_template_message():