* Pathlib support, takes a borrowed reference and returns a new one. * The new object may be the same as the old. */
| 11 | * The new object may be the same as the old. |
| 12 | */ |
| 13 | static inline PyObject * |
| 14 | NpyPath_PathlikeToFspath(PyObject *file) |
| 15 | { |
| 16 | static PyObject *os_PathLike = NULL; |
| 17 | static PyObject *os_fspath = NULL; |
| 18 | npy_cache_import("numpy.compat", "os_PathLike", &os_PathLike); |
| 19 | if (os_PathLike == NULL) { |
| 20 | return NULL; |
| 21 | } |
| 22 | npy_cache_import("numpy.compat", "os_fspath", &os_fspath); |
| 23 | if (os_fspath == NULL) { |
| 24 | return NULL; |
| 25 | } |
| 26 | |
| 27 | if (!PyObject_IsInstance(file, os_PathLike)) { |
| 28 | Py_INCREF(file); |
| 29 | return file; |
| 30 | } |
| 31 | return PyObject_CallFunctionObjArgs(os_fspath, file, NULL); |
| 32 | } |
| 33 | |
| 34 | #endif /* NUMPY_CORE_SRC_MULTIARRAY_METHODS_H_ */ |
no test coverage detected