Skip to content

raise AttributeError in __getattr__ if lookup fails #95

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

Merged
merged 4 commits into from
Dec 5, 2016
Merged
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 zarr/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ def _delitem_nosync(self, item):

def __getattr__(self, item):
# allow access to group members via dot notation
return self.__getitem__(item)
try:
return self.__getitem__(item)
except KeyError:
raise AttributeError

def group_keys(self):
"""Return an iterator over member names for groups only.
Expand Down
1 change: 1 addition & 0 deletions zarr/tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def _test_decode_lossy(self, arr, decimal, **kwargs):
order=order)
assert_array_almost_equal(arr, out, decimal=decimal)


test_arrays = [
np.arange(1000, dtype='i4'),
np.linspace(1000, 1001, 1000, dtype='f8'),
Expand Down
2 changes: 2 additions & 0 deletions zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ def test_getattr(self):
# test
eq(g1['foo'], g1.foo)
eq(g2['bar'], g2.bar)
# test that hasattr returns False instead of an exception (issue #88)
assert_false(hasattr(g1, 'unexistingattribute'))

def test_group_repr(self):
g = self.create_group()
Expand Down