Skip to content

Commit 02798e4

Browse files
authored
Merge pull request numpy#17290 from charris/cleanup-some-pystring-macros
MAINT: Cleanup some pystring macros
2 parents 7e9d603 + fcca6e7 commit 02798e4

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static NPY_INLINE npy_bool
4747
PySequence_NoString_Check(PyObject *op) {
4848
return
4949
PySequence_Check(op) &&
50-
!PyString_Check(op) &&
50+
!PyBytes_Check(op) &&
5151
!PyUnicode_Check(op) &&
5252
!PyArray_IsZeroDim(op);
5353
}

numpy/core/src/multiarray/dtypemeta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ datetime_known_scalar_types(
253253
* must take charge. Otherwise we would attempt casting which does not
254254
* truly support this. Only object arrays are special cased in this way.
255255
*/
256-
return (PyType_IsSubtype(pytype, &PyString_Type) ||
256+
return (PyType_IsSubtype(pytype, &PyBytes_Type) ||
257257
PyType_IsSubtype(pytype, &PyUnicode_Type));
258258
}
259259

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ array_fromfile(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
22262226
Py_DECREF(file);
22272227
return NULL;
22282228
}
2229-
if (PyString_Check(file) || PyUnicode_Check(file)) {
2229+
if (PyBytes_Check(file) || PyUnicode_Check(file)) {
22302230
Py_SETREF(file, npy_PyFile_OpenFile(file, "rb"));
22312231
if (file == NULL) {
22322232
Py_XDECREF(type);
@@ -2793,7 +2793,7 @@ array_einsum(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
27932793
arg0 = PyTuple_GET_ITEM(args, 0);
27942794

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

38783878
if (PyArray_TYPE(char_array) == NPY_STRING) {
3879-
method = PyObject_GetAttr((PyObject *)&PyString_Type, method_name);
3879+
method = PyObject_GetAttr((PyObject *)&PyBytes_Type, method_name);
38803880
}
38813881
else if (PyArray_TYPE(char_array) == NPY_UNICODE) {
38823882
method = PyObject_GetAttr((PyObject *)&PyUnicode_Type, method_name);
@@ -4337,7 +4337,7 @@ setup_scalartypes(PyObject *NPY_UNUSED(dict))
43374337
if (PyType_Ready(&PyComplex_Type) < 0) {
43384338
return -1;
43394339
}
4340-
if (PyType_Ready(&PyString_Type) < 0) {
4340+
if (PyType_Ready(&PyBytes_Type) < 0) {
43414341
return -1;
43424342
}
43434343
if (PyType_Ready(&PyUnicode_Type) < 0) {

numpy/core/src/multiarray/scalartypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static PyObject *
149149
gentype_add(PyObject *m1, PyObject* m2)
150150
{
151151
/* special case str.__radd__, which should not call array_add */
152-
if (PyString_Check(m1) || PyUnicode_Check(m1)) {
152+
if (PyBytes_Check(m1) || PyUnicode_Check(m1)) {
153153
Py_INCREF(Py_NotImplemented);
154154
return Py_NotImplemented;
155155
}

numpy/f2py/cfuncs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@
436436
PyObject *rv_cb_str = PyTuple_GetItem((tuple),(index));\\
437437
if (rv_cb_str == NULL)\\
438438
goto capi_fail;\\
439-
if (PyString_Check(rv_cb_str)) {\\
439+
if (PyBytes_Check(rv_cb_str)) {\\
440440
str[len-1]='\\0';\\
441-
STRINGCOPYN((str),PyString_AS_STRING((PyStringObject*)rv_cb_str),(len));\\
441+
STRINGCOPYN((str),PyString_AS_STRING((PyBytesObject*)rv_cb_str),(len));\\
442442
} else {\\
443443
PRINTPYOBJERR(rv_cb_str);\\
444444
PyErr_SetString(#modulename#_error,\"string object expected\");\\
@@ -655,7 +655,7 @@
655655
STRINGCOPYN(*str,PyArray_DATA(arr),*len+1);
656656
return 1;
657657
}
658-
if (PyString_Check(obj)) {
658+
if (PyBytes_Check(obj)) {
659659
tmp = obj;
660660
Py_INCREF(tmp);
661661
}
@@ -738,7 +738,7 @@
738738
}
739739
if (PyComplex_Check(obj))
740740
tmp = PyObject_GetAttrString(obj,\"real\");
741-
else if (PyString_Check(obj) || PyUnicode_Check(obj))
741+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
742742
/*pass*/;
743743
else if (PySequence_Check(obj))
744744
tmp = PySequence_GetItem(obj,0);
@@ -770,7 +770,7 @@
770770
}
771771
if (PyComplex_Check(obj))
772772
tmp = PyObject_GetAttrString(obj,\"real\");
773-
else if (PyString_Check(obj) || PyUnicode_Check(obj))
773+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
774774
/*pass*/;
775775
else if (PySequence_Check(obj))
776776
tmp = PySequence_GetItem(obj,0);
@@ -807,7 +807,7 @@
807807
}
808808
if (PyComplex_Check(obj))
809809
tmp = PyObject_GetAttrString(obj,\"real\");
810-
else if (PyString_Check(obj) || PyUnicode_Check(obj))
810+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
811811
/*pass*/;
812812
else if (PySequence_Check(obj))
813813
tmp = PySequence_GetItem(obj,0);
@@ -868,7 +868,7 @@
868868
}
869869
if (PyComplex_Check(obj))
870870
tmp = PyObject_GetAttrString(obj,\"real\");
871-
else if (PyString_Check(obj) || PyUnicode_Check(obj))
871+
else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
872872
/*pass*/;
873873
else if (PySequence_Check(obj))
874874
tmp = PySequence_GetItem(obj,0);
@@ -978,7 +978,7 @@
978978
(*v).r = PyLong_AsDouble(obj);
979979
return (!PyErr_Occurred());
980980
}
981-
if (PySequence_Check(obj) && !(PyString_Check(obj) || PyUnicode_Check(obj))) {
981+
if (PySequence_Check(obj) && !(PyBytes_Check(obj) || PyUnicode_Check(obj))) {
982982
PyObject *tmp = PySequence_GetItem(obj,0);
983983
if (tmp) {
984984
if (complex_double_from_pyobj(v,tmp,errmess)) {

tools/swig/numpy.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
if (py_obj == NULL ) return "C NULL value";
115115
if (py_obj == Py_None ) return "Python None" ;
116116
if (PyCallable_Check(py_obj)) return "callable" ;
117-
if (PyString_Check( py_obj)) return "string" ;
117+
if (PyBytes_Check( py_obj)) return "string" ;
118118
if (PyInt_Check( py_obj)) return "int" ;
119119
if (PyFloat_Check( py_obj)) return "float" ;
120120
if (PyDict_Check( py_obj)) return "dict" ;

0 commit comments

Comments
 (0)