Skip to content

Commit e4aef84

Browse files
apronchenkovcopybara-github
authored andcommitted
Simplify DataItem.__int__ and DataItem.__float__ by removing redundant type testing
PyNumber_Long and PyNumber_Float already contain such checks and optimisations ( [src](https://github.com/python/cpython/blob/main/Objects/abstract.c#L1516-L1518), [src](https://github.com/python/cpython/blob/main/Objects/abstract.c#L1595-L1597)). PiperOrigin-RevId: 714930002 Change-Id: Ie2fdf540b40764af7550d65bf10e809067d30d01
1 parent 9f2b2ca commit e4aef84

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

py/koladata/types/data_item.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ absl::Nullable<PyObject*> PyDataItem_int(PyObject* self) {
9393
if (py_obj == nullptr) {
9494
return nullptr;
9595
}
96-
if (PyLong_Check(py_obj.get())) {
97-
return py_obj.release();
98-
}
9996
return PyNumber_Long(py_obj.get());
10097
}
10198

@@ -113,9 +110,6 @@ absl::Nullable<PyObject*> PyDataItem_float(PyObject* self) {
113110
if (py_obj == nullptr) {
114111
return nullptr;
115112
}
116-
if (PyFloat_Check(py_obj.get())) {
117-
return py_obj.release();
118-
}
119113
return PyNumber_Float(py_obj.get());
120114
}
121115

0 commit comments

Comments
 (0)