Skip to content

Commit b8e6ac7

Browse files
authored
chore: reduce global Ruff ignore list (#326)
1 parent 418d1fd commit b8e6ac7

23 files changed

Lines changed: 240 additions & 224 deletions

File tree

examples/agent/strategies/function_calling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def _append_tool_invoke_response_text(
537537
return
538538

539539
if tool_invoke_response.type == ToolInvokeMessage.MessageType.BLOB:
540-
# TODO: convert to agent invoke message
540+
# Conversion to an agent invoke message remains open here.
541541
yield tool_invoke_response
542542
text_parts.append("Generated file ... ")
543543
return
@@ -556,7 +556,7 @@ def _handle_image_tool_response(
556556
).text
557557
yield from self._create_image_blob_message(file_info)
558558

559-
# TODO: convert to agent invoke message
559+
# Conversion to an agent invoke message remains open here.
560560
yield tool_invoke_response
561561
text_parts.append(
562562
"image has been created and sent to user already, "

examples/agent/strategies/react.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _invoke(self, parameters: dict[str, Any]) -> Generator[AgentInvokeMessage]:
202202
if isinstance(chunk, AgentScratchpadUnit.Action):
203203
action = chunk
204204
# detect action
205-
assert scratchpad.agent_response is not None
205+
scratchpad.agent_response = scratchpad.agent_response or ""
206206
scratchpad.agent_response += json.dumps(chunk.model_dump())
207207

208208
scratchpad.action_str = json.dumps(chunk.model_dump())
@@ -297,7 +297,7 @@ def _invoke(self, parameters: dict[str, Any]) -> Generator[AgentInvokeMessage]:
297297
scratchpad.observation = tool_invoke_response
298298
scratchpad.agent_response = tool_invoke_response
299299

300-
# TODO: convert to agent invoke message
300+
# Conversion to an agent invoke message remains open here.
301301
yield from additional_messages
302302
yield self.finish_log_message(
303303
log=tool_call_log,
@@ -393,20 +393,18 @@ def _organize_prompt_messages(
393393
assistant_messages = []
394394
else:
395395
assistant_message = AssistantPromptMessage(content="")
396+
assistant_content = cast("str", assistant_message.content)
396397
for unit in agent_scratchpad:
397398
if unit.is_final():
398-
assert isinstance(assistant_message.content, str)
399-
assistant_message.content += f"Final Answer: {unit.agent_response}"
399+
assistant_content += f"Final Answer: {unit.agent_response}"
400400
else:
401-
assert isinstance(assistant_message.content, str)
402-
assistant_message.content += f"Thought: {unit.thought}\n\n"
401+
assistant_content += f"Thought: {unit.thought}\n\n"
403402
if unit.action_str:
404-
assistant_message.content += f"Action: {unit.action_str}\n\n"
403+
assistant_content += f"Action: {unit.action_str}\n\n"
405404
if unit.observation:
406-
assistant_message.content += (
407-
f"Observation: {unit.observation}\n\n"
408-
)
405+
assistant_content += f"Observation: {unit.observation}\n\n"
409406

407+
assistant_message.content = assistant_content
410408
assistant_messages = [assistant_message]
411409

412410
# query messages

examples/github/provider/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _oauth_refresh_credentials(
7979
"""
8080
del redirect_uri
8181
del system_credentials
82-
# TODO: Implement the refresh credentials logic
82+
# Credential refresh is currently a no-op; credentials are returned unchanged.
8383
return ToolOAuthCredentials(credentials=credentials, expires_at=-1)
8484

8585
def _validate_credentials(self, credentials: dict) -> None:

examples/github_trigger/provider/github.py

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@
7979
"deploy_key",
8080
"watch",
8181
})
82+
EVENT_ALIASES = {
83+
**dict.fromkeys(SECRET_SCANNING_EVENTS, "secret_scanning"),
84+
**dict.fromkeys(REF_CHANGE_EVENTS, "ref_change"),
85+
}
86+
UNIFIED_EVENTS = (
87+
CORE_EVENTS
88+
| REVIEW_AND_CI_EVENTS
89+
| BRANCH_PROTECTION_EVENTS
90+
| ADDITIONAL_UNIFIED_EVENTS
91+
| frozenset({
92+
"push",
93+
"star",
94+
"code_scanning_alert",
95+
"commit_comment",
96+
"status",
97+
"deployment",
98+
"dependabot_alert",
99+
"repository_vulnerability_alert",
100+
"repository_ruleset",
101+
})
102+
)
82103

83104

84105
class GithubTrigger(Trigger):
@@ -111,12 +132,7 @@ def _dispatch_trigger_events(
111132
) -> list[str]:
112133
event_type = event_type.lower()
113134
action: str | None = payload.get("action")
114-
# Unified core events (breaking change): issues / issue_comment / pull_request
115-
if event_type in CORE_EVENTS:
116-
return [event_type]
117-
118-
# Unified review & CI events (breaking change)
119-
if event_type in REVIEW_AND_CI_EVENTS:
135+
if event_type in UNIFIED_EVENTS:
120136
return [event_type]
121137

122138
if event_type in ACTION_SUFFIX_EVENTS:
@@ -125,46 +141,9 @@ def _dispatch_trigger_events(
125141
raise TriggerDispatchError(msg)
126142
return [f"{event_type}_{action}"]
127143

128-
if event_type == "push":
129-
return ["push"]
130-
131-
if event_type == "star":
132-
return ["star"]
133-
134-
# Unified events without action splitting
135-
if event_type == "code_scanning_alert":
136-
return ["code_scanning_alert"]
137-
138-
if event_type in SECRET_SCANNING_EVENTS:
139-
return ["secret_scanning"]
140-
141-
if event_type in REF_CHANGE_EVENTS:
142-
return ["ref_change"]
143-
144-
if event_type == "commit_comment":
145-
return ["commit_comment"]
146-
147-
if event_type == "status":
148-
return ["status"]
149-
150-
if event_type == "deployment":
151-
return ["deployment"]
152-
153-
if event_type == "dependabot_alert":
154-
return ["dependabot_alert"]
155-
156-
if event_type == "repository_vulnerability_alert":
157-
return ["repository_vulnerability_alert"]
158-
159-
if event_type in BRANCH_PROTECTION_EVENTS:
160-
return [event_type]
161-
162-
if event_type == "repository_ruleset":
163-
return ["repository_ruleset"]
164-
165-
# Additional unified GitHub events (breaking change by design)
166-
if event_type in ADDITIONAL_UNIFIED_EVENTS:
167-
return [event_type]
144+
alias = EVENT_ALIASES.get(event_type)
145+
if alias:
146+
return [alias]
168147

169148
return []
170149

examples/gmail_trigger/events/gmail_message_added/gmail_message_added.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,7 @@ def _fetch_attachment_content(
348348
headers: Mapping[str, str],
349349
) -> tuple[bytes | None, int | None]:
350350
if inline_data:
351-
try:
352-
content = self._decode_base64url(inline_data)
353-
except binascii.Error:
354-
return None, None
355-
return content, len(content)
351+
return self._decode_attachment_data(inline_data)
356352

357353
attachment_id = attachment.get("attachmentId")
358354
if not attachment_id:
@@ -370,7 +366,11 @@ def _fetch_attachment_content(
370366
return None, None
371367

372368
data = response.json() or {}
373-
encoded = data.get("data")
369+
return self._decode_attachment_data(data.get("data"), data.get("size"))
370+
371+
def _decode_attachment_data(
372+
self, encoded: str | None, size: int | None = None
373+
) -> tuple[bytes | None, int | None]:
374374
if not encoded:
375375
return None, None
376376

@@ -379,7 +379,6 @@ def _fetch_attachment_content(
379379
except binascii.Error:
380380
return None, None
381381

382-
size = data.get("size")
383382
size_value = size if size is not None else len(content)
384383
return content, size_value
385384

examples/notion_datasource/datasources/utils/notion_extractor.py

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
"heading_2": "## ",
1010
"heading_3": "### ",
1111
}
12-
TEXT_PROPERTY_TYPES = frozenset({"rich_text", "title"})
13-
NAMED_PROPERTY_TYPES = frozenset({"select", "status"})
1412

1513

1614
class NotionExtractor:
@@ -49,8 +47,6 @@ def _load_data_as_documents(self, notion_obj_id: str, notion_obj_type: str) -> s
4947

5048
def _get_notion_database_data(self, database_id: str) -> str:
5149
"""Fetch all pages from a Notion database and return as a Markdown table."""
52-
assert self._notion_access_token is not None, "Notion access token is required"
53-
5450
# Retrieve database metadata
5551
database_data = self._client.retrieve_database(database_id=database_id)
5652

@@ -100,7 +96,6 @@ def _get_notion_database_data(self, database_id: str) -> str:
10096

10197
def _get_notion_block_data(self, page_id: str) -> str:
10298
"""Fetch and process Notion block data."""
103-
assert self._notion_access_token is not None, "Notion access token is required"
10499
result_lines_arr = []
105100

106101
# Retrieve page metadata
@@ -207,42 +202,46 @@ def _read_table_rows(self, block_id: str) -> str:
207202
def _extract_property_value(self, property_value: dict[str, Any]) -> object:
208203
"""Extract the value of a Notion property."""
209204
column_type = property_value["type"]
210-
if column_type == "multi_select":
211-
return ", ".join(option["name"] for option in property_value[column_type])
212-
if column_type in TEXT_PROPERTY_TYPES:
213-
return (
214-
property_value[column_type][0]["plain_text"]
215-
if property_value[column_type]
216-
else ""
217-
)
218-
if column_type in NAMED_PROPERTY_TYPES:
219-
return (
220-
property_value[column_type]["name"]
221-
if property_value[column_type]
222-
else ""
223-
)
224-
if column_type == "number":
225-
return property_value.get("number")
226-
if column_type == "date":
227-
date_data = property_value.get("date", {})
228-
return (
229-
{"start": date_data.get("start"), "end": date_data.get("end")}
230-
if date_data
231-
else None
232-
)
233-
if column_type == "formula":
234-
formula_value = property_value[column_type]
235-
return (
236-
formula_value.get("number")
237-
if isinstance(formula_value, dict)
238-
and formula_value.get("type") == "number"
239-
else formula_value
240-
)
241-
if column_type == "created_by":
242-
# Handle created_by type
243-
created_by_data = property_value.get("created_by", {})
244-
return created_by_data.get("name") if created_by_data else None
245-
return property_value[column_type]
205+
match column_type:
206+
case "multi_select":
207+
value = ", ".join(
208+
option["name"] for option in property_value[column_type]
209+
)
210+
case "rich_text" | "title":
211+
value = (
212+
property_value[column_type][0]["plain_text"]
213+
if property_value[column_type]
214+
else ""
215+
)
216+
case "select" | "status":
217+
value = (
218+
property_value[column_type]["name"]
219+
if property_value[column_type]
220+
else ""
221+
)
222+
case "number":
223+
value = property_value.get("number")
224+
case "date":
225+
date_data = property_value.get("date", {})
226+
value = (
227+
{"start": date_data.get("start"), "end": date_data.get("end")}
228+
if date_data
229+
else None
230+
)
231+
case "formula":
232+
formula_value = property_value[column_type]
233+
value = (
234+
formula_value.get("number")
235+
if isinstance(formula_value, dict)
236+
and formula_value.get("type") == "number"
237+
else formula_value
238+
)
239+
case "created_by":
240+
created_by_data = property_value.get("created_by", {})
241+
value = created_by_data.get("name") if created_by_data else None
242+
case _:
243+
value = property_value[column_type]
244+
return value
246245

247246
def _extract_cell_text(self, cell: list[dict]) -> str:
248247
"""Extract text content from a table cell."""

0 commit comments

Comments
 (0)