Skip to content

fix: Typing mismatch in filesystem write method #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sharat87
Copy link

@sharat87 sharat87 commented Jul 7, 2025

The function signature here is:

    def write(
        self,
        path_or_files: Union[str, List[WriteEntry]],
        data_or_user: Union[str, bytes, IO, Username] = "user",
        user_or_request_timeout: Optional[Union[float, Username]] = None,
        request_timeout_or_none: Optional[float] = None,
    ) -> Union[EntryInfo, List[EntryInfo]]:

Notice that path_or_files is str or a list of WriteEntry objects. But further down, if it is a str, we're turning it into a list of dicts, instead of into a list of WriteEntry objects. We also then proceed to use it like a dict. But this means if we pass a list[WriteEntry], as the type hint suggests, we get the following error:

  File ".../spike.py", line 49, in write_files
    box.files.write(
          ~~~~~~~~~~~~~~~^
        [
        ^
    ...<2 lines>...
        ],
        ^^
    )
    ^
  File ".../.venv/lib/python3.13/site-packages/e2b/sandbox_sync/filesystem/filesystem.py", line 213, in write
    file_path, file_data = file["path"], file["data"]
                           ~~~~^^^^^^^^
TypeError: 'WriteEntry' object is not subscriptable

This PR fixes this, by instead only creating/assuming WriteEntry objects in the list, as the type hint suggests.

Copy link

changeset-bot bot commented Jul 7, 2025

⚠️ No Changeset found

Latest commit: 23164f2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sharat87
Copy link
Author

sharat87 commented Jul 7, 2025

Note that this would mean we break backwards compatibility here. I can edit the fix to allow dicts to be passed in as well, if needed. Let me know.

@mishushakov
Copy link
Member

I think type WriteEntry is incorrect here. According to the docs is should be a (typed) dict:
https://e2b.dev/docs/filesystem/read-write#writing-multiple-files

If you can fix that incorrect type, we can proceed.

@mishushakov mishushakov self-assigned this Jul 8, 2025
@mishushakov mishushakov added the Improvement Improvement for current functionality label Jul 8, 2025
@ValentaTomas
Copy link
Member

One note here—this will probably also be in the async Python implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Improvement for current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants