Skip to content

Commit 39f204b

Browse files
apronchenkovcopybara-github
authored andcommitted
Integrate kd.types.DataItem with the ipython extension arolla.experimental.colab_safe_repr
This change list adds the attribute `DataItem._COLAB_HAS_SAFE_REPR = True` to fulfill the interface requirements for `arolla.experimental.colab_safe_repr`. PiperOrigin-RevId: 865144620 Change-Id: I6a1024b6383acbb33fb17a36383e90e098662e3b
1 parent f8788ac commit 39f204b

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

py/koladata/types/data_item.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ PyTypeObject* InitPyDataItemType() {
189189
};
190190

191191
PyObject* qvalue_subtype = PyType_FromSpec(&spec);
192+
PyObject_SetAttrString(qvalue_subtype, "_COLAB_HAS_SAFE_REPR", Py_True);
192193
if (!arolla::python::RegisterPyQValueSpecializationByKey(
193194
kDataItemQValueSpecializationKey, qvalue_subtype)) {
194195
return nullptr;

py/koladata/types/data_item_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ def test_int(self):
214214
self.assertAlmostEqual(int(ds(b'42')), 42)
215215
with self.assertRaisesRegex(ValueError, 'invalid literal for int'):
216216
int(ds('xyz'))
217-
with self.assertRaisesRegex(
218-
TypeError, r'must be a .*, not \'NoneType\''
219-
):
217+
with self.assertRaisesRegex(TypeError, r'must be a .*, not \'NoneType\''):
220218
int(ds(None))
221219
with self.assertRaisesRegex(
222220
ValueError, 'cannot be a DataItem that holds an ItemId'
@@ -234,7 +232,7 @@ def test_float(self):
234232
):
235233
float(ds(b'xyz'))
236234
with self.assertRaisesRegex(
237-
TypeError, 'must be a string or a real number, not \'NoneType\''
235+
TypeError, "must be a string or a real number, not 'NoneType'"
238236
):
239237
float(ds(None))
240238
with self.assertRaisesRegex(
@@ -326,6 +324,9 @@ def test_signatures(self):
326324
if callable(fn):
327325
_ = inspect.signature(fn) # Shouldn't raise.
328326

327+
def test_colab_has_safe_repr(self):
328+
self.assertTrue(hasattr(data_item.DataItem, '_COLAB_HAS_SAFE_REPR'))
329+
329330

330331
if __name__ == '__main__':
331332
absltest.main()

py/koladata/types/data_slice_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4443,6 +4443,8 @@ def test_functor_repr(self, f, expected_substrings):
44434443
for line in expected_substrings:
44444444
self.assertIn(line, fn_repr)
44454445

4446+
def test_colab_has_safe_repr(self):
4447+
self.assertFalse(hasattr(data_slice.DataSlice, '_COLAB_HAS_SAFE_REPR'))
44464448

44474449
if __name__ == '__main__':
44484450
absltest.main()

0 commit comments

Comments
 (0)