Skip to content

Commit 0ef7dd7

Browse files
authored
[chore] Ignore PLC0415 checks for existing codes (#76)
[chore] Ignore PLC0415 checks for existing codes
2 parents b885592 + ffcf05c commit 0ef7dd7

File tree

34 files changed

+346
-303
lines changed

34 files changed

+346
-303
lines changed

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ def instrumentation_dependencies(self) -> Collection[str]:
2020
def _instrument(self, **kwargs: Any) -> None:
2121
"""Enable AgentScope instrumentation."""
2222
if is_agentscope_v1():
23-
from opentelemetry.instrumentation.agentscope.v1 import (
23+
from opentelemetry.instrumentation.agentscope.v1 import ( # noqa: PLC0415
2424
AgentScopeV1Instrumentor,
2525
)
2626

2727
AgentScopeV1Instrumentor().instrument(**kwargs)
2828
else:
29-
from opentelemetry.instrumentation.agentscope.v0 import (
29+
from opentelemetry.instrumentation.agentscope.v0 import ( # noqa: PLC0415
3030
AgentScopeV0Instrumentor,
3131
)
3232

3333
AgentScopeV0Instrumentor().instrument(**kwargs)
3434

3535
def _uninstrument(self, **kwargs: Any) -> None:
3636
if is_agentscope_v1():
37-
from opentelemetry.instrumentation.agentscope.v1 import (
37+
from opentelemetry.instrumentation.agentscope.v1 import ( # noqa: PLC0415
3838
AgentScopeV1Instrumentor,
3939
)
4040

4141
AgentScopeV1Instrumentor().uninstrument(**kwargs)
4242
else:
43-
from opentelemetry.instrumentation.agentscope.v0 import (
43+
from opentelemetry.instrumentation.agentscope.v0 import ( # noqa: PLC0415
4444
AgentScopeV0Instrumentor,
4545
)
4646

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope/v0/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def _instrument(self, **kwargs: Any) -> None:
5252
)
5353

5454
def _uninstrument(self, **kwargs: Any) -> None:
55-
import agentscope.models.model
55+
import agentscope.models.model # noqa: PLC0415
5656

5757
unwrap(agentscope.models.model.ModelWrapperBase, "__init__")
58-
import agentscope.service.service_toolkit
58+
import agentscope.service.service_toolkit # noqa: PLC0415
5959

6060
unwrap(
6161
agentscope.service.service_toolkit.ServiceToolkit, "_execute_func"

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope/v0/_extractor.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ def extract(
2727
f"{agent.model_type}",
2828
)
2929

30-
for key in arguments.keys():
30+
for item in arguments.items():
31+
key, entry_value = item
3132
if key == "messages":
32-
messages = arguments[key]
33+
messages = entry_value
3334
for idx in range(len(messages)):
3435
message = messages[idx]
3536
if "role" in message:
@@ -44,7 +45,7 @@ def extract(
4445
)
4546

4647
if key == "tools":
47-
tools = arguments[key]
48+
tools = entry_value
4849
for idx in range(len(tools)):
4950
tool = tools[idx]
5051
yield (
@@ -53,17 +54,17 @@ def extract(
5354
)
5455

5556
if key == "texts":
56-
if isinstance(arguments[key], str):
57-
yield GenAIAttributes.GEN_AI_PROMPT, f"{arguments[key]}"
58-
elif isinstance(arguments[key], list):
59-
for idx, text in enumerate(arguments[key]):
57+
if isinstance(entry_value, str):
58+
yield GenAIAttributes.GEN_AI_PROMPT, f"{entry_value}"
59+
elif isinstance(entry_value, list):
60+
for idx, text in enumerate(entry_value):
6061
yield (
6162
f"{GenAIAttributes.GEN_AI_PROMPT}.{idx}",
6263
f"{text}",
6364
)
6465

6566
if key == "prompt":
66-
yield GenAIAttributes.GEN_AI_PROMPT, f"{arguments[key]}"
67+
yield GenAIAttributes.GEN_AI_PROMPT, f"{entry_value}"
6768

6869

6970
class ModelResponseExtractor(object):

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope/v1/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _instrument(self, **kwargs: Any) -> None:
154154
def _uninstrument(self, **kwargs: Any) -> None:
155155
"""移除插装。"""
156156
# 恢复被动态替换的方法
157-
from ._wrapper import (
157+
from ._wrapper import ( # noqa: PLC0415
158158
AgentScopeV1AgentWrapper,
159159
AgentScopeV1ChatModelWrapper,
160160
AgentScopeV1EmbeddingModelWrapper,
@@ -166,43 +166,43 @@ def _uninstrument(self, **kwargs: Any) -> None:
166166

167167
# 恢复直接包装的方法
168168
try:
169-
import agentscope.model
169+
import agentscope.model # noqa: PLC0415
170170

171171
unwrap(agentscope.model.ChatModelBase, "__init__")
172172
except Exception:
173173
pass
174174

175175
try:
176-
import agentscope.embedding
176+
import agentscope.embedding # noqa: PLC0415
177177

178178
unwrap(agentscope.embedding.EmbeddingModelBase, "__init__")
179179
except Exception:
180180
pass
181181

182182
try:
183-
import agentscope.agent
183+
import agentscope.agent # noqa: PLC0415
184184

185185
unwrap(agentscope.agent.AgentBase, "__init__")
186186
except Exception:
187187
pass
188188

189189
try:
190-
import agentscope.tool
190+
import agentscope.tool # noqa: PLC0415
191191

192192
unwrap(agentscope.tool.Toolkit, "call_tool_function")
193193
except Exception:
194194
pass
195195

196196
try:
197-
import agentscope.formatter
197+
import agentscope.formatter # noqa: PLC0415
198198

199199
unwrap(agentscope.formatter.FormatterBase, "format")
200200
except Exception:
201201
pass
202202

203203
# 恢复 setup_tracing
204204
try:
205-
import agentscope.tracing
205+
import agentscope.tracing # noqa: PLC0415
206206

207207
unwrap(agentscope.tracing, "setup_tracing")
208208
except Exception:

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope/v1/_response_attributes_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def _get_chatmodel_output_messages(
1717
list[dict[str, Any]]: 格式化的输出消息列表
1818
"""
1919
try:
20-
from agentscope.model import ChatResponse
20+
from agentscope.model import ChatResponse # noqa: PLC0415
2121

2222
if not isinstance(chat_response, ChatResponse):
2323
# logger.warning(f"Expected ChatResponse, got {type(chat_response)}")

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/tests/shared/version_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def skip_if_no_agentscope():
4545
"""如果没有安装agentscope则跳过测试"""
4646
try:
4747
# test the import of agentscope, skip the warning
48-
import agentscope # noqa: F401
48+
import agentscope # noqa: F401, PLC0415
4949

5050
return pytest.mark.skipif(False, reason="")
5151
except ImportError:

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/tests/v1/test_agentscope_v1.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from agentscope.message import Msg
1111
from agentscope.model import DashScopeChatModel
1212
from agentscope.tool import Toolkit, execute_shell_command
13+
from tests.shared.version_utils import skip_if_not_v1
1314

1415
from opentelemetry import trace as trace_api
1516
from opentelemetry.instrumentation.agentscope import AgentScopeInstrumentor
@@ -21,7 +22,6 @@
2122
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
2223
InMemorySpanExporter,
2324
)
24-
from tests.shared.version_utils import skip_if_not_v1
2525

2626

2727
@pytest.fixture(scope="module")
@@ -84,7 +84,7 @@ def test_agentscope_v1_basic(
8484
msg_task = Msg("user", "compute 1615114134*4343434343 for me", "user")
8585

8686
# 使用 asyncio 来运行异步函数
87-
import asyncio
87+
import asyncio # noqa: PLC0415
8888

8989
async def run_agent():
9090
response = await agent(msg_task)
@@ -114,7 +114,9 @@ async def run_agent():
114114
check_tool = True # noqa: F841
115115

116116
# 先检查是否至少有模型调用 span
117-
assert check_model, f"Model call span not found. Available spans: {[span.name for span in spans]}"
117+
assert check_model, (
118+
f"Model call span not found. Available spans: {[span.name for span in spans]}"
119+
)
118120

119121

120122
@skip_if_not_v1()
@@ -142,7 +144,7 @@ def test_agentscope_v1_simple_chat(
142144

143145
msg_task = Msg("user", "Hello, how are you?", "user")
144146

145-
import asyncio
147+
import asyncio # noqa: PLC0415
146148

147149
async def run_agent():
148150
response = await agent(msg_task)
@@ -162,9 +164,9 @@ async def run_agent():
162164
spans = in_memory_span_exporter.get_finished_spans()
163165
print(f"Simple chat spans: {[span.name for span in spans]}")
164166
model_spans = [span for span in spans if span.name.startswith("chat ")]
165-
assert (
166-
len(model_spans) > 0
167-
), f"No model call span found. Available spans: {[span.name for span in spans]}"
167+
assert len(model_spans) > 0, (
168+
f"No model call span found. Available spans: {[span.name for span in spans]}"
169+
)
168170

169171

170172
@skip_if_not_v1()
@@ -185,7 +187,7 @@ def test_agentscope_v1_model_direct(
185187
# 直接调用模型(使用字典格式避免 Msg 对象问题)
186188
messages = [{"role": "user", "content": "Hello, what is 1+1?"}]
187189

188-
import asyncio
190+
import asyncio # noqa: PLC0415
189191

190192
async def call_model():
191193
response = await model(messages)
@@ -205,9 +207,9 @@ async def call_model():
205207
spans = in_memory_span_exporter.get_finished_spans()
206208
print(f"Direct model spans: {[span.name for span in spans]}")
207209
model_spans = [span for span in spans if span.name.startswith("chat ")]
208-
assert (
209-
len(model_spans) > 0
210-
), f"No model call span found. Available spans: {[span.name for span in spans]}"
210+
assert len(model_spans) > 0, (
211+
f"No model call span found. Available spans: {[span.name for span in spans]}"
212+
)
211213

212214

213215
@skip_if_not_v1()
@@ -228,7 +230,7 @@ def test_agentscope_v1_span_attributes(
228230
# 直接调用模型(使用字典格式)
229231
messages = [{"role": "user", "content": "Simple test message"}]
230232

231-
import asyncio
233+
import asyncio # noqa: PLC0415
232234

233235
async def call_model():
234236
response = await model(messages)
@@ -245,9 +247,9 @@ async def call_model():
245247
print(f"Attributes test spans: {[span.name for span in spans]}")
246248
model_spans = [span for span in spans if span.name.startswith("chat ")]
247249

248-
assert (
249-
len(model_spans) > 0
250-
), f"No model call span found. Available spans: {[span.name for span in spans]}"
250+
assert len(model_spans) > 0, (
251+
f"No model call span found. Available spans: {[span.name for span in spans]}"
252+
)
251253

252254
# 验证第一个ModelCall span的基本属性
253255
model_span = model_spans[0]

instrumentation-loongsuite/loongsuite-instrumentation-agno/src/opentelemetry/instrumentation/agno/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,21 @@ def _instrument(self, **kwargs: Any) -> None:
9898

9999
def _uninstrument(self, **kwargs: Any) -> None:
100100
# Unwrap the agent call function
101-
import agno.agent
101+
import agno.agent # noqa: PLC0415
102102

103103
unwrap(agno.agent.Agent, "_run")
104104
unwrap(agno.agent.Agent, "_arun")
105105
unwrap(agno.agent.Agent, "_run_stream")
106106
unwrap(agno.agent.Agent, "_arun_stream")
107107

108108
# Unwrap the function call
109-
import agno.tools.function
109+
import agno.tools.function # noqa: PLC0415
110110

111111
unwrap(agno.tools.function.FunctionCall, "execute")
112112
unwrap(agno.tools.function.FunctionCall, "aexecute")
113113

114114
# Unwrap the model
115-
import agno.models.base
115+
import agno.models.base # noqa: PLC0415
116116

117117
unwrap(agno.models.base.Model, "response")
118118
unwrap(agno.models.base.Model, "aresponse")

instrumentation-loongsuite/loongsuite-instrumentation-agno/src/opentelemetry/instrumentation/agno/_extractor.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def extract(
3131

3232
if agent.tools:
3333
tool_names = []
34-
from agno.tools.function import Function
35-
from agno.tools.toolkit import Toolkit
34+
from agno.tools.function import Function # noqa: PLC0415
35+
from agno.tools.toolkit import Toolkit # noqa: PLC0415
3636

3737
for tool in agent.tools:
3838
if isinstance(tool, Function):
@@ -45,14 +45,15 @@ def extract(
4545
tool_names.append(str(tool))
4646
yield GenAIAttributes.GEN_AI_TOOL_NAME, ", ".join(tool_names)
4747

48-
for key in arguments.keys():
48+
for item in arguments.items():
49+
key, entry_value = item
4950
if key == "run_response":
5051
yield (
5152
GenAIAttributes.GEN_AI_RESPONSE_ID,
52-
f"{arguments[key].run_id}",
53+
f"{entry_value.run_id}",
5354
)
5455
elif key == "run_messages":
55-
messages = arguments[key].messages
56+
messages = entry_value.messages
5657
for idx in range(len(messages)):
5758
message = messages[idx]
5859
yield (
@@ -62,7 +63,7 @@ def extract(
6263
elif key == "response_format":
6364
yield (
6465
GenAIAttributes.GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT,
65-
f"{arguments[key]}",
66+
f"{entry_value}",
6667
)
6768

6869

@@ -131,22 +132,23 @@ def extract(
131132
f"{json.dumps(request_kwargs, indent=2)}",
132133
)
133134

134-
for key in arguments.keys():
135+
for item in arguments.items():
136+
key, entry_value = item
135137
if key == "response_format":
136138
yield (
137139
GenAIAttributes.GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT,
138-
f"{arguments[key]}",
140+
f"{entry_value}",
139141
)
140142
elif key == "messages":
141-
messages = arguments["messages"]
143+
messages = entry_value
142144
for idx in range(len(messages)):
143145
message = messages[idx]
144146
yield (
145147
f"{GenAIAttributes.GEN_AI_PROMPT}.{idx}.message",
146148
f"{json.dumps(message.to_dict(), indent=2)}",
147149
)
148150
elif key == "tools":
149-
tools = arguments["tools"]
151+
tools = entry_value
150152
for idx in range(len(tools)):
151153
yield (
152154
f"{GenAIAttributes.GEN_AI_TOOL_DESCRIPTION}.{idx}",

instrumentation-loongsuite/loongsuite-instrumentation-agno/tests/test_agno.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ def test_agno(in_memory_span_exporter: InMemorySpanExporter):
7777
check_model = True
7878
if "ToolCall" in span.name:
7979
check_tool = True
80-
assert (
81-
check_agent and check_model and check_tool
82-
), "Agent, Model or ToolCall span not found"
80+
assert check_agent and check_model and check_tool, (
81+
"Agent, Model or ToolCall span not found"
82+
)

0 commit comments

Comments
 (0)