整理代码
This commit is contained in:
@@ -43,8 +43,17 @@ class BaseApiHandler(BaseNodeHandler[T]):
|
||||
_schema: Any
|
||||
|
||||
def __init__(self, **handler_config: Any):
|
||||
# 子类应该在调用 super().__init__() 之前或之后设置 _node_type, _node_class, _schema
|
||||
super().__init__()
|
||||
# 子类可直接传入 node_class;少数特殊场景可显式覆盖 schema/node_type。
|
||||
node_class = handler_config.pop("node_class", None)
|
||||
node_type = handler_config.pop("node_type", None)
|
||||
schema = handler_config.pop("schema", None)
|
||||
|
||||
if node_class is not None and node_type is None:
|
||||
node_type = getattr(node_class, "node_type", None)
|
||||
if node_class is not None and schema is None:
|
||||
schema = getattr(node_class, "schema", None)
|
||||
|
||||
super().__init__(node_type=node_type, node_class=node_class, schema=schema)
|
||||
self.api_client: 'ApiClient' = None # type: ignore # 由 DataSource 注入
|
||||
self.poll_mode: str = "async" # async | sync
|
||||
self._collection: 'DataCollection' = None # type: ignore # 由 DataSource 注入
|
||||
@@ -67,7 +76,7 @@ class BaseApiHandler(BaseNodeHandler[T]):
|
||||
|
||||
def set_collection(self, collection: 'DataCollection') -> None:
|
||||
"""设置 Collection(由 DataSource 调用)"""
|
||||
self._collection = collection
|
||||
super().set_collection(collection)
|
||||
|
||||
def ensure_api_client(self) -> 'ApiClient':
|
||||
if self.api_client is None:
|
||||
|
||||
Reference in New Issue
Block a user