Skip to content

Commit 3221954

Browse files
authored
Safe repr for Group (#1890)
1 parent 8d52e32 commit 3221954

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Next
22

3+
## Bug Fixes
4+
5+
* Add safe `Group.__repr__` [#1890](https://github.com/TileDB-Inc/TileDB-Py/pull/1890)
6+
37
## Improvements
48

59
* Warn when `os.fork()` is used in the presence of a Tiledb context [#1876](https://github.com/TileDB-Inc/TileDB-Py/pull/1876/files).

tiledb/group.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ def __contains__(self, member: str) -> bool:
389389
return self._has_member(member)
390390

391391
def __repr__(self):
392+
# use safe repr if pybind11 constructor failed
393+
if self._ctx is None:
394+
return object.__repr__(self)
395+
392396
return self._dump(True)
393397

394398
def __enter__(self):

tiledb/tests/test_group.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def test_set_config(self):
342342
with tiledb.Group(group_uri, config=cfg) as G:
343343
assert len(G) == sz
344344

345+
def test_group_does_not_exist(self):
346+
with self.assertRaises(tiledb.TileDBError):
347+
tiledb.Group("does-not-exist")
348+
345349

346350
class GroupMetadataTest(GroupTestCase):
347351
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)