def nullable_int(num): """ casts input to an int if not an accepted null value. See :func:tab.tab.cast_null """ try: return cast_null(num) except TypeError: pass return int(num)
def test_cast_null_error(self): with self.assertRaises(TypeError): cast_null('f')
def test_cast_null_ok(self): self.assertEqual(None, cast_null('none')) self.assertEqual(None, cast_null(None))
def nullable_int(row): try: row = int(row) except ValueError: row = tab.cast_null(row) return row
def soft_cast_null(value): try: return tab.cast_null(value) except TypeError: return value