Skip to content

Commit

Permalink
Merge pull request #17290 from charris/cleanup-some-pystring-macros
Browse files Browse the repository at this point in the history
MAINT: Cleanup some pystring macros
  • Loading branch information
mattip committed Sep 11, 2020
2 parents 7e9d603 + fcca6e7 commit 02798e4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static NPY_INLINE npy_bool
PySequence_NoString_Check(PyObject *op) {
return
PySequence_Check(op) &&
!PyString_Check(op) &&
!PyBytes_Check(op) &&
!PyUnicode_Check(op) &&
!PyArray_IsZeroDim(op);
}
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/dtypemeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ datetime_known_scalar_types(
* must take charge. Otherwise we would attempt casting which does not
* truly support this. Only object arrays are special cased in this way.
*/
return (PyType_IsSubtype(pytype, &PyString_Type) ||
return (PyType_IsSubtype(pytype, &PyBytes_Type) ||
PyType_IsSubtype(pytype, &PyUnicode_Type));
}

Expand Down
8 changes: 4 additions & 4 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ array_fromfile(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
Py_DECREF(file);
return NULL;
}
if (PyString_Check(file) || PyUnicode_Check(file)) {
if (PyBytes_Check(file) || PyUnicode_Check(file)) {
Py_SETREF(file, npy_PyFile_OpenFile(file, "rb"));
if (file == NULL) {
Py_XDECREF(type);
Expand Down Expand Up @@ -2793,7 +2793,7 @@ array_einsum(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
arg0 = PyTuple_GET_ITEM(args, 0);

/* einsum('i,j', a, b), einsum('i,j->ij', a, b) */
if (PyString_Check(arg0) || PyUnicode_Check(arg0)) {
if (PyBytes_Check(arg0) || PyUnicode_Check(arg0)) {
nop = einsum_sub_op_from_str(args, &str_obj, &subscripts, op);
}
/* einsum(a, [0], b, [1]), einsum(a, [0], b, [1], [0,1]) */
Expand Down Expand Up @@ -3876,7 +3876,7 @@ _vec_string(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *NPY_UNUSED(kw
}

if (PyArray_TYPE(char_array) == NPY_STRING) {
method = PyObject_GetAttr((PyObject *)&PyString_Type, method_name);
method = PyObject_GetAttr((PyObject *)&PyBytes_Type, method_name);
}
else if (PyArray_TYPE(char_array) == NPY_UNICODE) {
method = PyObject_GetAttr((PyObject *)&PyUnicode_Type, method_name);
Expand Down Expand Up @@ -4337,7 +4337,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
if (PyType_Ready(&PyComplex_Type) < 0) {
return -1;
}
if (PyType_Ready(&PyString_Type) < 0) {
if (PyType_Ready(&PyBytes_Type) < 0) {
return -1;
}
if (PyType_Ready(&PyUnicode_Type) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static PyObject *
gentype_add(PyObject *m1, PyObject* m2)
{
/* special case str.__radd__, which should not call array_add */
if (PyString_Check(m1) || PyUnicode_Check(m1)) {
if (PyBytes_Check(m1) || PyUnicode_Check(m1)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
Expand Down
16 changes: 8 additions & 8 deletions numpy/f2py/cfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@
PyObject *rv_cb_str = PyTuple_GetItem((tuple),(index));\\
if (rv_cb_str == NULL)\\
goto capi_fail;\\
if (PyString_Check(rv_cb_str)) {\\
if (PyBytes_Check(rv_cb_str)) {\\
str[len-1]='\\0';\\
STRINGCOPYN((str),PyString_AS_STRING((PyStringObject*)rv_cb_str),(len));\\
STRINGCOPYN((str),PyString_AS_STRING((PyBytesObject*)rv_cb_str),(len));\\
} else {\\
PRINTPYOBJERR(rv_cb_str);\\
PyErr_SetString(#modulename#_error,\"string object expected\");\\
Expand Down Expand Up @@ -655,7 +655,7 @@
STRINGCOPYN(*str,PyArray_DATA(arr),*len+1);
return 1;
}
if (PyString_Check(obj)) {
if (PyBytes_Check(obj)) {
tmp = obj;
Py_INCREF(tmp);
}
Expand Down Expand Up @@ -738,7 +738,7 @@
}
if (PyComplex_Check(obj))
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyString_Check(obj) || PyUnicode_Check(obj))
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
Expand Down Expand Up @@ -770,7 +770,7 @@
}
if (PyComplex_Check(obj))
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyString_Check(obj) || PyUnicode_Check(obj))
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
Expand Down Expand Up @@ -807,7 +807,7 @@
}
if (PyComplex_Check(obj))
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyString_Check(obj) || PyUnicode_Check(obj))
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
Expand Down Expand Up @@ -868,7 +868,7 @@
}
if (PyComplex_Check(obj))
tmp = PyObject_GetAttrString(obj,\"real\");
else if (PyString_Check(obj) || PyUnicode_Check(obj))
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
/*pass*/;
else if (PySequence_Check(obj))
tmp = PySequence_GetItem(obj,0);
Expand Down Expand Up @@ -978,7 +978,7 @@
(*v).r = PyLong_AsDouble(obj);
return (!PyErr_Occurred());
}
if (PySequence_Check(obj) && !(PyString_Check(obj) || PyUnicode_Check(obj))) {
if (PySequence_Check(obj) && !(PyBytes_Check(obj) || PyUnicode_Check(obj))) {
PyObject *tmp = PySequence_GetItem(obj,0);
if (tmp) {
if (complex_double_from_pyobj(v,tmp,errmess)) {
Expand Down
2 changes: 1 addition & 1 deletion tools/swig/numpy.i
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
if (py_obj == NULL ) return "C NULL value";
if (py_obj == Py_None ) return "Python None" ;
if (PyCallable_Check(py_obj)) return "callable" ;
if (PyString_Check( py_obj)) return "string" ;
if (PyBytes_Check( py_obj)) return "string" ;
if (PyInt_Check( py_obj)) return "int" ;
if (PyFloat_Check( py_obj)) return "float" ;
if (PyDict_Check( py_obj)) return "dict" ;
Expand Down

0 comments on commit 02798e4

Please sign in to comment.