Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion diskcache/fanout.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def directory(self):
def __getattr__(self, name):
safe_names = {'timeout', 'disk'}
valid_name = name in DEFAULT_SETTINGS or name in safe_names
assert valid_name, 'cannot access {} in cache shard'.format(name)
if not valid_name:
raise AttributeError(
'cannot access {} in cache shard'.format(name)
)
return getattr(self._shards[0], name)

@cl.contextmanager
Expand Down
10 changes: 10 additions & 0 deletions tests/test_fanout.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def test_init(cache):
cache.check()


def test_getattr_invalid_name_raises_attribute_error(cache):
# Regression test: __getattr__ used to raise AssertionError for an
# unknown attribute, which breaks hasattr() (it only treats
# AttributeError as "attribute not found").
with pytest.raises(AttributeError):
cache.__slots__

assert not hasattr(cache, '__slots__')


def test_init_path(cache):
path = pathlib.Path(cache.directory)
other = dc.FanoutCache(path)
Expand Down