Skip to content

Commit 1c9aaf4

Browse files
authored
Merge pull request #1657 from tisnik/lcore-2095-replace-ternary-if-with-or-operator
LCORE-2095: Replace ternary `if` with `or` operator
2 parents 5c49c58 + 52e15e0 commit 1c9aaf4

6 files changed

Lines changed: 12 additions & 24 deletions

File tree

src/app/endpoints/conversations_v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def build_conversation_turn_from_cache_entry(entry: CacheEntry) -> ConversationT
269269
]
270270

271271
# Extract tool calls and results (default to empty lists if None)
272-
tool_calls = entry.tool_calls if entry.tool_calls else []
273-
tool_results = entry.tool_results if entry.tool_results else []
272+
tool_calls = entry.tool_calls or []
273+
tool_results = entry.tool_results or []
274274

275275
return ConversationTurn(
276276
messages=messages,

src/app/endpoints/vector_stores.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ async def add_file_to_vector_store( # pylint: disable=too-many-locals,too-many-
636636
"Vector store file created - ID: %s, status: %s, last_error: %s",
637637
vs_file.id,
638638
vs_file.status,
639-
vs_file.last_error if vs_file.last_error else "None",
639+
vs_file.last_error or "None",
640640
)
641641

642642
return VectorStoreFileResponse(

src/utils/conversations.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ def _build_tool_call_summary_from_item( # pylint: disable=too-many-return-state
174174
args = parse_arguments_string(mcp_call_item.arguments)
175175
if mcp_call_item.server_label:
176176
args["server_label"] = mcp_call_item.server_label
177-
content = (
178-
mcp_call_item.error
179-
if mcp_call_item.error
180-
else (mcp_call_item.output if mcp_call_item.output else "")
181-
)
177+
content = mcp_call_item.error or (mcp_call_item.output or "")
182178

183179
return (
184180
ToolCallSummary(

src/utils/responses.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ async def get_mcp_tools(
740740
server_label=mcp_server.name,
741741
server_url=mcp_server.url,
742742
require_approval="never",
743-
headers=headers if headers else None,
743+
headers=headers or None,
744744
authorization=authorization,
745745
)
746746
)
@@ -801,7 +801,7 @@ def apply_mcp_headers_to_explicit_tools(
801801
out.append(
802802
mcp_tool.model_copy(
803803
update={
804-
"headers": headers if headers else None,
804+
"headers": headers or None,
805805
"authorization": authorization,
806806
}
807807
)
@@ -861,7 +861,7 @@ def parse_referenced_documents( # pylint: disable=too-many-locals
861861

862862
if doc_title or doc_url:
863863
# Treat empty string as None for URL to satisfy Optional[AnyUrl]
864-
final_url = doc_url if doc_url else None
864+
final_url = doc_url or None
865865
if (final_url, doc_title) not in seen_docs:
866866
documents.append(
867867
ReferencedDocument(
@@ -1018,11 +1018,7 @@ def build_tool_call_summary( # pylint: disable=too-many-return-statements,too-m
10181018
args = parse_arguments_string(mcp_call_item.arguments)
10191019
if mcp_call_item.server_label:
10201020
args["server_label"] = mcp_call_item.server_label
1021-
content = (
1022-
mcp_call_item.error
1023-
if mcp_call_item.error
1024-
else (mcp_call_item.output if mcp_call_item.output else "")
1025-
)
1021+
content = mcp_call_item.error or (mcp_call_item.output or "")
10261022

10271023
return ToolCallSummary(
10281024
id=mcp_call_item.id,
@@ -1141,11 +1137,7 @@ def build_tool_result_from_mcp_output_item_done(
11411137
Returns:
11421138
ToolResultSummary for the MCP call
11431139
"""
1144-
content = (
1145-
output_item.error
1146-
if output_item.error
1147-
else (output_item.output if output_item.output else "")
1148-
)
1140+
content = output_item.error or (output_item.output or "")
11491141
return ToolResultSummary(
11501142
id=output_item.id,
11511143
status="success" if output_item.error is None else "failure",
@@ -1213,7 +1205,7 @@ def _build_chunk_attributes(result: Any) -> Optional[dict[str, Any]]:
12131205
if not attributes:
12141206
return None
12151207
if isinstance(attributes, dict):
1216-
return attributes if attributes else None
1208+
return attributes or None
12171209
return None
12181210

12191211

src/utils/vector_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def _convert_solr_chunks_to_rag_format(
671671
content=chunk.content,
672672
source=constants.OKP_RAG_ID,
673673
score=score,
674-
attributes=attributes if attributes else None,
674+
attributes=attributes or None,
675675
)
676676
)
677677

tests/e2e/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def cluster_lightspeed_config_dir() -> str:
104104
"""
105105
raw = os.getenv("E2E_LIGHTSPEED_CONFIG_DIR", _DEFAULT_CLUSTER_LIGHTSPEED_CONFIG_DIR)
106106
stripped = raw.strip()
107-
return stripped if stripped else _DEFAULT_CLUSTER_LIGHTSPEED_CONFIG_DIR
107+
return stripped or _DEFAULT_CLUSTER_LIGHTSPEED_CONFIG_DIR
108108

109109

110110
def cluster_lightspeed_config_path(filename: str) -> str:

0 commit comments

Comments
 (0)