Skip to content

Commit 70f7c1d

Browse files
authored
Merge pull request #95 from vincentschut/fix_88
raise AttributeError in __getattr__ if lookup fails
2 parents befd48d + a7b0850 commit 70f7c1d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

zarr/hierarchy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ def _delitem_nosync(self, item):
319319

320320
def __getattr__(self, item):
321321
# allow access to group members via dot notation
322-
return self.__getitem__(item)
322+
try:
323+
return self.__getitem__(item)
324+
except KeyError:
325+
raise AttributeError
323326

324327
def group_keys(self):
325328
"""Return an iterator over member names for groups only.

zarr/tests/test_codecs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def _test_decode_lossy(self, arr, decimal, **kwargs):
149149
order=order)
150150
assert_array_almost_equal(arr, out, decimal=decimal)
151151

152+
152153
test_arrays = [
153154
np.arange(1000, dtype='i4'),
154155
np.linspace(1000, 1001, 1000, dtype='f8'),

zarr/tests/test_hierarchy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ def test_getattr(self):
492492
# test
493493
eq(g1['foo'], g1.foo)
494494
eq(g2['bar'], g2.bar)
495+
# test that hasattr returns False instead of an exception (issue #88)
496+
assert_false(hasattr(g1, 'unexistingattribute'))
495497

496498
def test_group_repr(self):
497499
g = self.create_group()

0 commit comments

Comments
 (0)