mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 09:05:04 +08:00
🐛 fix import recursion when same plugin and file name (fix #401)
This commit is contained in:
parent
ddd96271b0
commit
8e6f8fada8
@ -251,8 +251,8 @@ class MessageSegment(Mapping, abc.ABC, Generic[T_Message]):
|
|||||||
- 说明: 消息段数据
|
- 说明: 消息段数据
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@abc.abstractmethod
|
||||||
def get_message_class(cls) -> Type[T_Message]:
|
def get_message_class(cls) -> Type[T_Message]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -330,8 +330,8 @@ class Message(List[T_MessageSegment], abc.ABC):
|
|||||||
else:
|
else:
|
||||||
self.extend(self._construct(message))
|
self.extend(self._construct(message))
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@abc.abstractmethod
|
||||||
def get_segment_class(cls) -> Type[T_MessageSegment]:
|
def get_segment_class(cls) -> Type[T_MessageSegment]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class PluginManager:
|
|||||||
if not prefix.startswith(_internal_space.__name__):
|
if not prefix.startswith(_internal_space.__name__):
|
||||||
prefix = _internal_space.__name__
|
prefix = _internal_space.__name__
|
||||||
module = _InternalModule(prefix, self)
|
module = _InternalModule(prefix, self)
|
||||||
sys.modules[module.__name__] = module
|
sys.modules[module.__name__] = module # type: ignore
|
||||||
setattr(_internal_space, internal_id, module)
|
setattr(_internal_space, internal_id, module)
|
||||||
return module
|
return module
|
||||||
|
|
||||||
@ -177,11 +177,11 @@ class PluginFinder(MetaPathFinder):
|
|||||||
newname = manager._rewrite_module_name(fullname)
|
newname = manager._rewrite_module_name(fullname)
|
||||||
if newname:
|
if newname:
|
||||||
spec = PathFinder.find_spec(
|
spec = PathFinder.find_spec(
|
||||||
newname, [*manager.search_path, *(path or sys.path)],
|
newname, path or [*manager.search_path, *sys.path],
|
||||||
target)
|
target)
|
||||||
if spec:
|
if spec:
|
||||||
spec.loader = PluginLoader(manager, newname,
|
spec.loader = PluginLoader( # type: ignore
|
||||||
spec.origin)
|
manager, newname, spec.origin)
|
||||||
return spec
|
return spec
|
||||||
index -= 1
|
index -= 1
|
||||||
return None
|
return None
|
||||||
|
@ -289,19 +289,6 @@ class MessageChain(BaseMessage[MessageSegment]):
|
|||||||
f'Type {type(message).__name__} is not supported in mirai adapter.'
|
f'Type {type(message).__name__} is not supported in mirai adapter.'
|
||||||
)
|
)
|
||||||
|
|
||||||
@overrides(BaseMessage)
|
|
||||||
def reduce(self):
|
|
||||||
"""
|
|
||||||
:说明:
|
|
||||||
|
|
||||||
忽略为空的消息段, 合并相邻的纯文本消息段
|
|
||||||
"""
|
|
||||||
for index, segment in enumerate(self):
|
|
||||||
segment: MessageSegment
|
|
||||||
if segment.is_text() and not str(segment).strip():
|
|
||||||
self.pop(index)
|
|
||||||
super().reduce()
|
|
||||||
|
|
||||||
@overrides(BaseMessage)
|
@overrides(BaseMessage)
|
||||||
def _construct(
|
def _construct(
|
||||||
self, message: Union[List[Dict[str, Any]], Iterable[MessageSegment]]
|
self, message: Union[List[Dict[str, Any]], Iterable[MessageSegment]]
|
||||||
|
Loading…
Reference in New Issue
Block a user