refactor: 统一类型注解风格并优化代码结构
- 将裸 except 改为显式 Exception 捕获 - 用列表推导式替换冗余 for 循环 - 为类属性添加 ClassVar 注解 - 统一 Union/Optional 写法为 | - 移除未使用的导入 - 修复 SQLAlchemy 空值比较语法 - 优化字符串拼接与字典更新逻辑 - 补充缺失的 noqa 注释与异常链 BREAKING CHANGE: 所有插件基类的类级字段现要求显式 ClassVar 注解,自定义插件需同步更新
This commit is contained in:
@@ -63,12 +63,12 @@ async def check_database():
|
||||
null_situation = await session.execute(
|
||||
select(func.count())
|
||||
.select_from(Expression)
|
||||
.where(Expression.situation == None)
|
||||
.where(Expression.situation is None)
|
||||
)
|
||||
null_style = await session.execute(
|
||||
select(func.count())
|
||||
.select_from(Expression)
|
||||
.where(Expression.style == None)
|
||||
.where(Expression.style is None)
|
||||
)
|
||||
|
||||
null_sit_count = null_situation.scalar()
|
||||
@@ -102,7 +102,7 @@ async def check_database():
|
||||
.limit(20)
|
||||
)
|
||||
|
||||
styles = [s for s in unique_styles.scalars()]
|
||||
styles = list(unique_styles.scalars())
|
||||
for style in styles:
|
||||
print(f" - {style}")
|
||||
|
||||
|
||||
@@ -29,15 +29,14 @@ async def analyze_style_fields():
|
||||
print(f"\n总共检查 {len(expressions)} 条记录\n")
|
||||
|
||||
# 按类型分类
|
||||
style_examples = []
|
||||
|
||||
for expr in expressions:
|
||||
if expr.type == "style":
|
||||
style_examples.append({
|
||||
"situation": expr.situation,
|
||||
"style": expr.style,
|
||||
"length": len(expr.style) if expr.style else 0
|
||||
})
|
||||
style_examples = [
|
||||
{
|
||||
"situation": expr.situation,
|
||||
"style": expr.style,
|
||||
"length": len(expr.style) if expr.style else 0
|
||||
}
|
||||
for expr in expressions if expr.type == "style"
|
||||
]
|
||||
|
||||
print("📋 Style 类型样例 (前15条):")
|
||||
print("="*60)
|
||||
|
||||
@@ -21,11 +21,11 @@ mcp = FastMCP("Demo Server")
|
||||
@mcp.tool()
|
||||
def add(a: int, b: int) -> int:
|
||||
"""将两个数字相加
|
||||
|
||||
|
||||
Args:
|
||||
a: 第一个数字
|
||||
b: 第二个数字
|
||||
|
||||
|
||||
Returns:
|
||||
两个数字的和
|
||||
"""
|
||||
@@ -35,11 +35,11 @@ def add(a: int, b: int) -> int:
|
||||
@mcp.tool()
|
||||
def multiply(a: float, b: float) -> float:
|
||||
"""将两个数字相乘
|
||||
|
||||
|
||||
Args:
|
||||
a: 第一个数字
|
||||
b: 第二个数字
|
||||
|
||||
|
||||
Returns:
|
||||
两个数字的乘积
|
||||
"""
|
||||
@@ -49,10 +49,10 @@ def multiply(a: float, b: float) -> float:
|
||||
@mcp.tool()
|
||||
def get_weather(city: str) -> str:
|
||||
"""获取指定城市的天气信息(模拟)
|
||||
|
||||
|
||||
Args:
|
||||
city: 城市名称
|
||||
|
||||
|
||||
Returns:
|
||||
天气信息字符串
|
||||
"""
|
||||
@@ -73,11 +73,11 @@ def get_weather(city: str) -> str:
|
||||
@mcp.tool()
|
||||
def echo(message: str, repeat: int = 1) -> str:
|
||||
"""重复输出一条消息
|
||||
|
||||
|
||||
Args:
|
||||
message: 要重复的消息
|
||||
repeat: 重复次数,默认为 1
|
||||
|
||||
|
||||
Returns:
|
||||
重复后的消息
|
||||
"""
|
||||
@@ -87,10 +87,10 @@ def echo(message: str, repeat: int = 1) -> str:
|
||||
@mcp.tool()
|
||||
def check_prime(number: int) -> bool:
|
||||
"""检查一个数字是否为质数
|
||||
|
||||
|
||||
Args:
|
||||
number: 要检查的数字
|
||||
|
||||
|
||||
Returns:
|
||||
如果是质数返回 True,否则返回 False
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user