fsspec / fsspec/filesystem_spec

Error when processing file mode string

Open
#1,425 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.4k
Forks
490
Avg merge
2d 3h
Merged PRs (30d)
38

Description

In the memory filesystem there is an error if you try to open it with r+b mode saying this mode is not supported.

However this mode is apparently supported (https://github.com/fsspec/filesystem_spec/blob/master/fsspec/implementations/memory.py#L178).

What I think is happening is that the mode=r+b(or mode=rb+) argument is being processed and transformed internally to r+b and then the comparison to rb+ fails.

(I assume that it should work for any order for the characters in the mode string: rb+ or r+b).

Reproducer:

import fsspec
uri = "memory://path/file"
open_file = fsspec.open(uri, mode="rb+")  # r+b doesn't work either
assert open_file.mode == "rb+"
file = open_file.open() # raises ValueError

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with fsspec/implementations/memory.py around line 178 and run the reproducer from the issue for both rb+ and r+b modes. Trace where the mode is normalized before the support check; done means both equivalent mode strings open successfully without the unsupported-mode error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.