Skip to content

Commit 238ee9a

Browse files
committed
Fix remaining linting issues in test_reasoning_content.py
1 parent 76f3699 commit 238ee9a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/test_reasoning_content.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import AsyncIterator
4-
from typing import Any, Dict, cast
4+
from typing import Any, cast
55

66
import pytest
77
from openai.types.chat import ChatCompletion, ChatCompletionChunk, ChatCompletionMessage
@@ -25,7 +25,7 @@
2525

2626

2727
# Helper functions to create test objects consistently
28-
def create_content_delta(content: str) -> Dict[str, Any]:
28+
def create_content_delta(content: str) -> dict[str, Any]:
2929
"""Create a delta dictionary with regular content"""
3030
return {
3131
"content": content,
@@ -34,7 +34,7 @@ def create_content_delta(content: str) -> Dict[str, Any]:
3434
"tool_calls": None
3535
}
3636

37-
def create_reasoning_delta(content: str) -> Dict[str, Any]:
37+
def create_reasoning_delta(content: str) -> dict[str, Any]:
3838
"""Create a delta dictionary with reasoning content. The Only difference is reasoning_content"""
3939
return {
4040
"content": None,
@@ -45,7 +45,7 @@ def create_reasoning_delta(content: str) -> Dict[str, Any]:
4545
}
4646

4747

48-
def create_chunk(delta: Dict[str, Any], include_usage: bool = False) -> ChatCompletionChunk:
48+
def create_chunk(delta: dict[str, Any], include_usage: bool = False) -> ChatCompletionChunk:
4949
"""Create a ChatCompletionChunk with the given delta"""
5050
# Create a ChoiceDelta object from the dictionary
5151
delta_obj = ChoiceDelta(
@@ -54,11 +54,13 @@ def create_chunk(delta: Dict[str, Any], include_usage: bool = False) -> ChatComp
5454
function_call=delta.get("function_call"),
5555
tool_calls=delta.get("tool_calls"),
5656
)
57-
57+
5858
# Add reasoning_content attribute dynamically if present in the delta
5959
if "reasoning_content" in delta:
60-
setattr(delta_obj, "reasoning_content", delta["reasoning_content"])
61-
60+
# Use direct assignment for the reasoning_content attribute
61+
delta_obj_any = cast(Any, delta_obj)
62+
delta_obj_any.reasoning_content = delta["reasoning_content"]
63+
6264
# Create the chunk
6365
chunk = ChatCompletionChunk(
6466
id="chunk-id",
@@ -67,7 +69,7 @@ def create_chunk(delta: Dict[str, Any], include_usage: bool = False) -> ChatComp
6769
object="chat.completion.chunk",
6870
choices=[Choice(index=0, delta=delta_obj)],
6971
)
70-
72+
7173
if include_usage:
7274
chunk.usage = CompletionUsage(
7375
completion_tokens=4,
@@ -76,7 +78,7 @@ def create_chunk(delta: Dict[str, Any], include_usage: bool = False) -> ChatComp
7678
completion_tokens_details=CompletionTokensDetails(reasoning_tokens=2),
7779
prompt_tokens_details=PromptTokensDetails(cached_tokens=0),
7880
)
79-
81+
8082
return chunk
8183

8284

@@ -276,7 +278,7 @@ async def patched_fetch_response(self, *args, **kwargs):
276278
# verify the final response contains the content
277279
response_event = output_events[-1]
278280
assert response_event.type == "response.completed"
279-
281+
280282
# should only have the message, not an empty reasoning item
281283
assert len(response_event.response.output) == 1
282284
assert isinstance(response_event.response.output[0], ResponseOutputMessage)

0 commit comments

Comments
 (0)