Skip to content

Commit 76d5211

Browse files
author
ChidcGithub
committed
Fix lint errors: remove unused imports, fix bare except
- Remove unused imports across all modules - Replace bare except with except Exception - Fix E721: use 'is' for type comparison - Fix E731: replace lambda with def function - Fix F841: remove unused variable assignment
1 parent 9f4e1ee commit 76d5211

File tree

11 files changed

+16
-24
lines changed

11 files changed

+16
-24
lines changed

cognipy/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import argparse
88
import sys
9-
import os
109
from pathlib import Path
1110

1211
from .transformer import transform_code
@@ -121,7 +120,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
121120
exec(code_obj, self.locals)
122121
except SystemExit:
123122
raise
124-
except:
123+
except Exception:
125124
self.showtraceback()
126125

127126
return False

cognipy/decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Callable, get_type_hints, Any, Optional
99
import inspect
1010

11-
from .runtime import cognitive_call, CognitiveContext
11+
from .runtime import cognitive_call
1212

1313

1414
def cognitive(func: Callable = None, *, model: Optional[str] = None) -> Callable:

cognipy/determinism.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from dataclasses import dataclass, field
1111
from enum import Enum
1212
from typing import (
13-
Any, Optional, List, Dict, Type, Callable,
14-
Generic, TypeVar, get_origin, get_args, Union, TYPE_CHECKING
13+
Any, List, Dict, Type, TypeVar, TYPE_CHECKING
1514
)
1615
from pydantic import BaseModel, ValidationError as PydanticValidationError
1716

@@ -82,7 +81,7 @@ def validate(self, value: Any) -> ValidationResult:
8281
if not isinstance(value, self.expected_type):
8382
# 尝试类型转换
8483
try:
85-
if self.expected_type == bool:
84+
if self.expected_type is bool:
8685
if isinstance(value, str):
8786
if value.lower() in ('true', 'yes', '1'):
8887
value = True
@@ -482,7 +481,7 @@ def deterministic_call(
482481
ValidationResult 对象
483482
"""
484483
from .runtime import cognitive_call
485-
from .reflection import with_reflection, ReflectionStatus
484+
from .reflection import with_reflection
486485

487486
# 构建带约束的提示
488487
constrained_prompt = f"{prompt}\n\n约束: {constraint.to_prompt()}\n\n请严格按照约束要求回答。"

cognipy/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
import time
99
from abc import ABC, abstractmethod
10-
from dataclasses import dataclass, field, asdict
10+
from dataclasses import dataclass, field
1111
from pathlib import Path
1212
from typing import Optional, List, Dict, Any
1313
from enum import Enum

cognipy/providers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from enum import Enum
1111
import json
1212

13-
from .runtime import LLMConfig
1413
from .streaming import StreamChunk, StreamStatus
1514

1615

cognipy/reflection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
"""
66

77
from dataclasses import dataclass, field
8-
from typing import Optional, Callable, List, Any
8+
from typing import Optional, Callable, List
99
from enum import Enum
1010

11-
from .memory import MemoryStore, Message, MessageRole
1211
from .runtime import cognitive_call, CognitiveContext
1312

1413

cognipy/runtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"""
66

77
from dataclasses import dataclass, field
8-
from typing import Any, Optional, Callable, Union, TYPE_CHECKING
8+
from typing import Optional, TYPE_CHECKING
99
import os
1010

1111
if TYPE_CHECKING:
12-
from .memory import MemoryStore, InMemoryStore, FileStore
12+
from .memory import MemoryStore
1313

1414

1515
@dataclass

cognipy/scheduler.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
from enum import Enum
1616
from typing import (
1717
Any, Optional, Callable, Coroutine, List, Dict,
18-
TypeVar, Generic, Awaitable, Union
18+
TypeVar, Generic, Union
1919
)
20-
from concurrent.futures import TimeoutError as AsyncTimeoutError
21-
import functools
2220

2321
from .runtime import LLMConfig, CognitiveContext
2422

@@ -171,7 +169,8 @@ async def submit(
171169
if asyncio.iscoroutine(coro_or_factory):
172170
# 直接传入协程,无法重试
173171
coro = coro_or_factory
174-
coro_factory = lambda: coro
172+
def coro_factory():
173+
return coro
175174
effective_max_retries = 0 # 无法重试
176175
else:
177176
# 传入工厂函数
@@ -239,7 +238,7 @@ async def _execute_task(self, task: ScheduledTask):
239238
if task.callback:
240239
try:
241240
task.callback(result)
242-
except Exception as e:
241+
except Exception:
243242
# 回调错误不影响任务状态
244243
pass
245244

cognipy/streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from dataclasses import dataclass, field
8-
from typing import AsyncIterator, Iterator, Optional, Callable, Any, List
8+
from typing import AsyncIterator, Iterator, Optional, Callable, List
99
from enum import Enum
1010
import asyncio
1111

cognipy/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
import json
88
import inspect
9-
from dataclasses import dataclass, field
9+
from dataclasses import dataclass
1010
from typing import (
1111
Any, Callable, Dict, List, Optional, Type, Union,
1212
get_type_hints, get_origin, get_args
1313
)
1414
from enum import Enum
1515
from functools import wraps
1616

17-
from .runtime import LLMConfig, CognitiveContext, cognitive_call
17+
from .runtime import LLMConfig, CognitiveContext
1818

1919

2020
class ToolType(Enum):

0 commit comments

Comments
 (0)