Get the length hint of a Python object. Returns 0 when this cannot be determined.
| 2559 | /// Get the length hint of a Python object. |
| 2560 | /// Returns 0 when this cannot be determined. |
| 2561 | inline size_t len_hint(handle h) { |
| 2562 | ssize_t result = PyObject_LengthHint(h.ptr(), 0); |
| 2563 | if (result < 0) { |
| 2564 | // Sometimes a length can't be determined at all (eg generators) |
| 2565 | // In which case simply return 0 |
| 2566 | PyErr_Clear(); |
| 2567 | return 0; |
| 2568 | } |
| 2569 | return static_cast<size_t>(result); |
| 2570 | } |
| 2571 | |
| 2572 | inline str repr(handle h) { |
| 2573 | PyObject *str_value = PyObject_Repr(h.ptr()); |