Skip to content

Fix _cat_file / _cat_ranges not discoverable on WholeFileCacheFileSystem class#2010

Merged
martindurant merged 2 commits intofsspec:masterfrom
hadim:fix/wholefile-cat-file-class-attribute
Apr 14, 2026
Merged

Fix _cat_file / _cat_ranges not discoverable on WholeFileCacheFileSystem class#2010
martindurant merged 2 commits intofsspec:masterfrom
hadim:fix/wholefile-cat-file-class-attribute

Conversation

@hadim
Copy link
Copy Markdown
Contributor

@hadim hadim commented Apr 11, 2026

Fixes #2009

Problem

hasattr(type(fs), '_cat_file') returns False for WholeFileCacheFileSystem, even though hasattr(fs, '_cat_file') returns True. This is because CachingFileSystem.__getattribute__ intercepts attribute access at the instance level, but the method is never defined on the class itself.

Libraries like universal_pathlib and zarr inspect capabilities via type(fs) rather than the instance, which leads to AttributeError.

Fix

Two changes:

  1. Move _cat_file and _cat_ranges from SimpleCacheFileSystem up to WholeFileCacheFileSystem. Both classes use the same whole-file caching logic (check cache, download if missing, read locally). SimpleCacheFileSystem inherits them unchanged.

  2. Guard the whitelist in __getattribute__: the whitelist is shared across the hierarchy, but some entries only exist on certain subclasses. When a whitelisted method is not on type(self), we now fall through to the wrapped filesystem delegation instead of returning a lambda that would raise AttributeError.

Note to maintainers

If this instance-only delegation is intentional by design, or if you'd prefer a different approach, happy to hear your guidance. We can adjust or close this accordingly.

Move _cat_file and _cat_ranges from SimpleCacheFileSystem to
WholeFileCacheFileSystem so that these methods are discoverable
via type(fs) and not only via instance attribute lookup.

Also add a guard in CachingFileSystem.__getattribute__ so that
whitelisted methods not defined on the current subclass fall
through to the wrapped filesystem delegation instead of returning
a broken lambda.

Closes fsspec#2009
@hadim hadim changed the title Fix _cat_file and _cat_ranges missing on WholeFileCacheFileSystem class Fix _cat_file / _cat_ranges not discoverable on WholeFileCacheFileSystem class Apr 11, 2026
@martindurant martindurant merged commit 2853792 into fsspec:master Apr 14, 2026
11 checks passed
@hadim hadim deleted the fix/wholefile-cat-file-class-attribute branch April 15, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WholeFileCacheFileSystem: _cat_file exists on instance but not on class

2 participants