| 1606 | _convert_from_str(PyObject *obj, int align); |
| 1607 | |
| 1608 | static PyArray_Descr * |
| 1609 | _convert_from_any(PyObject *obj, int align) |
| 1610 | { |
| 1611 | /* default */ |
| 1612 | if (obj == Py_None) { |
| 1613 | return PyArray_DescrFromType(NPY_DEFAULT_TYPE); |
| 1614 | } |
| 1615 | else if (PyArray_DescrCheck(obj)) { |
| 1616 | PyArray_Descr *ret = (PyArray_Descr *)obj; |
| 1617 | Py_INCREF(ret); |
| 1618 | return ret; |
| 1619 | } |
| 1620 | else if (PyType_Check(obj)) { |
| 1621 | return _convert_from_type(obj); |
| 1622 | } |
| 1623 | /* or a typecode string */ |
| 1624 | else if (PyBytes_Check(obj)) { |
| 1625 | /* Allow bytes format strings: convert to unicode */ |
| 1626 | PyObject *obj2 = PyUnicode_FromEncodedObject(obj, NULL, NULL); |
| 1627 | if (obj2 == NULL) { |
| 1628 | /* Convert the exception into a TypeError */ |
| 1629 | if (PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) { |
| 1630 | PyErr_SetString(PyExc_TypeError, |
| 1631 | "data type not understood"); |
| 1632 | } |
| 1633 | return NULL; |
| 1634 | } |
| 1635 | PyArray_Descr *ret = _convert_from_str(obj2, align); |
| 1636 | Py_DECREF(obj2); |
| 1637 | return ret; |
| 1638 | } |
| 1639 | else if (PyUnicode_Check(obj)) { |
| 1640 | return _convert_from_str(obj, align); |
| 1641 | } |
| 1642 | else if (PyTuple_Check(obj)) { |
| 1643 | /* or a tuple */ |
| 1644 | if (Py_EnterRecursiveCall( |
| 1645 | " while trying to convert the given data type from" |
| 1646 | " a tuple object" ) != 0) { |
| 1647 | return NULL; |
| 1648 | } |
| 1649 | PyArray_Descr *ret = _convert_from_tuple(obj, align); |
| 1650 | Py_LeaveRecursiveCall(); |
| 1651 | return ret; |
| 1652 | } |
| 1653 | else if (PyList_Check(obj)) { |
| 1654 | /* or a list */ |
| 1655 | if (Py_EnterRecursiveCall( |
| 1656 | " while trying to convert the given data type from" |
| 1657 | " a list object" ) != 0) { |
| 1658 | return NULL; |
| 1659 | } |
| 1660 | PyArray_Descr *ret = _convert_from_array_descr(obj, align); |
| 1661 | Py_LeaveRecursiveCall(); |
| 1662 | return ret; |
| 1663 | } |
| 1664 | else if (PyDict_Check(obj) || PyDictProxy_Check(obj)) { |
| 1665 | /* or a dictionary */ |
no test coverage detected