fix(files): remove erroneous tuple check from is_file_content type guard (#1318)#1408
Open
xodn348 wants to merge 1 commit intoanthropics:mainfrom
Open
fix(files): remove erroneous tuple check from is_file_content type guard (#1318)#1408xodn348 wants to merge 1 commit intoanthropics:mainfrom
xodn348 wants to merge 1 commit intoanthropics:mainfrom
Conversation
…ard (anthropics#1318) The is_file_content TypeGuard included isinstance(obj, tuple) despite FileContent being defined as Union[IO[bytes], bytes, PathLike]. This caused _transform_file to enter the FileContent branch for tuple inputs, skipping the tuple-specific branch where PathLike elements are resolved via read_file_content. Removing the tuple check allows tuples like (filename, Path(...), content_type) to correctly reach the is_tuple_t branch and have their PathLike elements properly opened before being passed to httpx.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1318.
client.beta.files.upload(file=("foo.txt", Path("foo.txt"), "text/plain"))fails because theis_file_contenttype guard incorrectly matches tuples, preventing the tuple-specific branch in_transform_filefrom handlingPathLikeresolution.Problem
is_file_content()includedisinstance(obj, tuple)despiteFileContentbeing defined asUnion[IO[bytes], bytes, PathLike](no tuple). This caused_transform_fileto enter theFileContentbranch for tuple inputs, skipping theis_tuple_tbranch whereread_file_contentproperly resolvesPathLikeelements.Fix
Remove the erroneous
isinstance(obj, tuple)check fromis_file_content, aligning the runtime type guard with the staticFileContenttype definition. Tuples now correctly reach theis_tuple_tbranch and have theirPathLikeelements opened before being passed to httpx.Change