mirror of
				https://github.com/nonebot/nonebot2.git
				synced 2025-10-30 22:46:40 +00:00 
			
		
		
		
	🐛 修复当消息与不支持的类型相加时抛出的异常类型错误 (#1166)
This commit is contained in:
		| @@ -186,7 +186,7 @@ class Message(List[TMS], abc.ABC): | |||||||
|         elif isinstance(other, Iterable): |         elif isinstance(other, Iterable): | ||||||
|             self.extend(other) |             self.extend(other) | ||||||
|         else: |         else: | ||||||
|             raise ValueError(f"Unsupported type: {type(other)}")  # pragma: no cover |             raise TypeError(f"Unsupported type {type(other)!r}") | ||||||
|         return self |         return self | ||||||
|  |  | ||||||
|     @overload |     @overload | ||||||
|   | |||||||
| @@ -11,11 +11,11 @@ def test_template_basis(): | |||||||
|  |  | ||||||
| def test_template_message(): | def test_template_message(): | ||||||
|     Message = make_fake_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 |     @template.add_format_spec | ||||||
|     def custom(input: str) -> str: |     def custom(input: str) -> str: | ||||||
|         return input + "-custom!" |         return f"{input}-custom!" | ||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         template.add_format_spec(custom) |         template.add_format_spec(custom) | ||||||
| @@ -24,12 +24,17 @@ def test_template_message(): | |||||||
|     else: |     else: | ||||||
|         raise AssertionError("Should raise ValueError") |         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) |     formatted = template.format(**format_args) | ||||||
|  |  | ||||||
|     assert template.format_map(format_args) == formatted |     assert template.format_map(format_args) == formatted | ||||||
|     assert formatted.extract_plain_text() == "custom-custom!text" |     assert formatted.extract_plain_text() == "custom-custom!text/114" | ||||||
|     assert str(formatted) == "custom-custom!text[fake:image]" |     assert str(formatted) == "custom-custom!text[fake:image]/114" | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_rich_template_message(): | def test_rich_template_message(): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user