Iterable vs List in the request datatypes
Problem
Consider the definition of `MessageParam`: [code block] The `Iterable` here doesn't allow me to write any kind of useful transformations over the datatype without changing its state in the process: [code block] which is quite inconvenient and could easily lead to all kind of errors. Is there any reason to use `Iterable` here and in other request/response datatypes? Could it be replaced with `List`?
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Iterable vs List in the request datatypes
> Namely it'd also be a breaking change so if we do decide to change to Sequence it likely won't be shipped quickly unfortunately as some users may be relying on just being able to pass an iterable. I feel the pain of breaking changes. I wonder which use cases warrant the generality of iterable though... > Maybe a workaround for now would be to add a pydantic post-validator that turns content in
Trust Score
2 verifications
- 1
> Namely it'd also be a breaking change so if we do decide to change to Sequence
> Namely it'd also be a breaking change so if we do decide to change to Sequence it likely won't be shipped quickly unfortunately as some users may be relying on just being able to pass an iterable.
- 2
I feel the pain of breaking changes.
I wonder which use cases warrant the generality of iterable though...
- 3
> Maybe a workaround for now would be to add a pydantic post-validator that turn
> Maybe a workaround for now would be to add a pydantic post-validator that turns content into a list so you don't have to handle the conversion everywhere? Sorry this is difficult!
- 4
No worries, I've switched to `dataclasses`. Pydantic was an overkill in my case
No worries, I've switched to `dataclasses`. Pydantic was an overkill in my case anyway.
Validation
Resolved in anthropics/anthropic-sdk-python GitHub issue #656. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep