Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/messages_stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S rye run python
#!/usr/bin/env -S uv run python

import asyncio

Expand Down
7 changes: 5 additions & 2 deletions src/anthropic/lib/streaming/_messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import builtins
from types import TracebackType
from typing import TYPE_CHECKING, Any, Type, Generic, Callable, cast
from typing_extensions import Self, Iterator, Awaitable, AsyncIterator, assert_never
Expand Down Expand Up @@ -445,7 +446,9 @@ def accumulate_event(
),
)
if not isinstance(cast(Any, event), BaseModel):
raise TypeError(f"Unexpected event runtime type, after deserialising twice - {event} - {type(event)}")
raise TypeError(
f"Unexpected event runtime type, after deserialising twice - {event} - {builtins.type(event)}"
)

if current_snapshot is None:
if event.type == "message_start":
Expand All @@ -458,7 +461,7 @@ def accumulate_event(
current_snapshot.content.append(
cast(
Any, # Pydantic does not support generic unions at runtime
construct_type(type_=ParsedContentBlock, value=event.content_block.model_dump()),
construct_type(type_=ParsedContentBlock, value=event.content_block.to_dict()),
),
)
elif event.type == "content_block_delta":
Expand Down