3030import re
3131from dataclasses import dataclass , field
3232from enum import Enum , auto
33- from typing import Any
33+ from typing import TYPE_CHECKING , Any
3434
3535from autowsgr .infra .logger import get_logger
3636from autowsgr .types import Formation
3737
3838
39+ if TYPE_CHECKING :
40+ from collections .abc import Mapping
41+
42+
3943# 允许在规则中出现的舰种标识符
4044_log = get_logger ('combat.recognition' )
4145
@@ -134,7 +138,7 @@ def __post_init__(self) -> None:
134138 if self .op not in _OPERATORS :
135139 raise ValueError (f"不支持的操作符: '{ self .op } ',支持: { list (_OPERATORS )} " )
136140
137- def evaluate (self , context : dict [str , int | float ]) -> bool :
141+ def evaluate (self , context : Mapping [str , int | float ]) -> bool :
138142 """在给定上下文中评估此条件。"""
139143 if '+' in self .field :
140144 parts = [p .strip () for p in self .field .split ('+' )]
@@ -159,7 +163,7 @@ class Rule:
159163 conditions : list [Condition ]
160164 action : RuleAction
161165
162- def evaluate (self , context : dict [str , int | float ]) -> bool :
166+ def evaluate (self , context : Mapping [str , int | float ]) -> bool :
163167 """所有条件是否均满足。"""
164168 return all (c .evaluate (context ) for c in self .conditions )
165169
@@ -184,7 +188,7 @@ class RuleEngine:
184188 rules : list [Rule ] = field (default_factory = list )
185189 default : RuleAction = field (default_factory = RuleAction .no_action )
186190
187- def evaluate (self , context : dict [str , int | float ]) -> RuleAction :
191+ def evaluate (self , context : Mapping [str , int | float ]) -> RuleAction :
188192 """对敌方编成上下文评估所有规则。
189193
190194 Parameters
0 commit comments