8000 Merge pull request #15232 from sethtroisi/remove_python3_part3 · numpy/numpy@c1f1bc9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1f1bc9

Browse files
authored
Merge pull request #15232 from sethtroisi/remove_python3_part3
MAINT: Cleaning up PY_MAJOR_VERSION/PY_VERSION_HEX
2 parents 1d9595f + 24189be commit c1f1bc9

18 files changed

+1
-292
lines changed

doc/Py3K.rst.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,7 @@ The Py2/Py3 compatible structure definition looks like::
357357
(binaryfunc)0, /*nb_true_divide*/
358358
0, /*nb_inplace_floor_divide*/
359359
0, /*nb_inplace_true_divide*/
360-
#if PY_VERSION_HEX >= 0x02050000
361360
(unaryfunc)NULL, /*nb_index*/
362-
#endif
363361
};
364362

365363

doc/source/user/c-info.ufunc-tutorial.rst

Expand all lines: doc/source/user/c-info.ufunc-tutorial.rst
Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ the module.
137137
138138
139139
/* This initiates the module using the above definitions. */
140-
#if PY_VERSION_HEX >= 0x03000000
141140
static struct PyModuleDef moduledef = {
142141
PyModuleDef_HEAD_INIT,
143142
"spam",
@@ -159,17 +158,6 @@ the module.
159158
}
160159
return m;
161160
}
162-
#else
163-
PyMODINIT_FUNC initspam(void)
164-
{
165-
PyObject *m;
166-
167-
m = Py_InitModule("spam", SpamMethods);
168-
if (m == NULL) {
169-
return;
170-
}
171-
}
172-
#endif
173161
174162
To use the setup.py file, place setup.py and spammodule.c in the same
175163
folder. Then python setup.py build will build the module to import,
@@ -322,7 +310,6 @@ the primary thing that must be changed to create your own ufunc.
322310
323311
static void *data[1] = {NULL};
324312
325-
#if PY_VERSION_HEX >= 0x03000000
326313
static struct PyModuleDef moduledef = {
327314
PyModuleDef_HEAD_INIT,
328315
"npufunc",
@@ -357,30 +344,6 @@ the primary thing that must be changed to create your own ufunc.
357344
358345
return m;
359346
}
360-
#else
361-
PyMODINIT_FUNC initnpufunc(void)
362-
{
363-
PyObject *m, *logit, *d;
364-
365-
366-
m = Py_InitModule("npufunc", LogitMethods);
367-
if (m == NULL) {
368-
return;
369-
}
370-
371-
import_array();
372-
import_umath();
373-
374-
logit = PyUFunc_FromFuncAndData(funcs, data, types, 1, 1, 1,
375-
PyUFunc_None, "logit",
376-
"logit_docstring", 0);
377-
378-
d = PyModule_GetDict(m);
379-
380-
PyDict_SetItemString(d, "logit", logit);
381-
Py_DECREF(logit);
382-
}
383-
#endif
384347
385348
This is a setup.py file for the above code. As before, the module
386349
can be build via calling python setup.py build at the command prompt,
@@ -601,7 +564,6 @@ the primary thing that must be changed to create your own ufunc.
601564
NPY_LONGDOUBLE, NPY_LONGDOUBLE};
602565
static void *data[4] = {NULL, NULL, NULL, NULL};
603566
604-
#if PY_VERSION_HEX >= 0x03000000
605567
static struct PyModuleDef moduledef = {
606568
PyModuleDef_HEAD_INIT,
607569
"npufunc",
@@ -636,30 +598,6 @@ the primary thing that must be changed to create your own ufunc.
636598
637599
return m;
638600
}
639-
#else
640-
PyMODINIT_FUNC initnpufunc(void)
641-
{
642-
PyObject *m, *logit, *d;
643-
644-
645-
m = Py_InitModule("npufunc", LogitMethods);
646-
if (m == NULL) {
647-
return;
648-
}
649-
650-
import_array();
651-
import_umath();
652-
653-
logit = PyUFunc_FromFuncAndData(funcs, data, types, 4, 1, 1,
654-
PyUFunc_None, "logit",
655-
"logit_docstring", 0);
656-
657-
d = PyModule_GetDict(m);
658-
659-
PyDict_SetItemString(d, "logit", logit);
660-
Py_DECREF(logit);
661-
}
662-
#endif
663601
664602
This is a setup.py file for the above code. As before, the module
665603
can be build via calling python setup.py build at the command prompt,
@@ -824,7 +762,6 @@ as well as all other properties of a ufunc.
824762
825763
static void *data[1] = {NULL};
826764
827-
#if PY_VERSION_HEX >= 0x03000000
828765
static struct PyModuleDef moduledef = {
829766
PyModuleDef_HEAD_INIT,
830767
"npufunc",
@@ -859,30 +796,6 @@ as well as all other properties of a ufunc.
859796
860797
return m;
861798
}
862-
#else
863-
PyMODINIT_FUNC initnpufunc(void)
864-
{
865-
PyObject *m, *logit, *d;
866-
867-
868-
m = Py_InitModule("npufunc", LogitMethods);
869-
if (m == NULL) {
870-
return;
871-
}
872-
873-
import_array();
874-
import_umath();
875-
876-
logit = PyUFunc_FromFuncAndData(funcs, data, types, 1, 2, 2,
877-
PyUFunc_None, "logit",
878-
"logit_docstring", 0);
879-
880-
d = PyModule_GetDict(m);
881-
882-
PyDict_SetItemString(d, "logit", logit);
883-
Py_DECREF(logit);
884-
}
885-
#endif
886799
887800
888801
.. _`sec:NumPy-struct-dtype`:

numpy/core/code_generators/generate_numpy_api.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,12 @@
5757
return -1;
5858
}
5959
60-
#if PY_VERSION_HEX >= 0x03000000
6160
if (!PyCapsule_CheckExact(c_api)) {
6261
PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCapsule object");
6362
Py_DECREF(c_api);
6463
return -1;
6564
}
6665
PyArray_API = (void **)PyCapsule_GetPointer(c_api, NULL);
67-
#else
68-
if (!PyCObject_Check(c_api)) {
69-
PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCObject object");
70-
Py_DECREF(c_api);
71-
return -1;
72-
}
73-
PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);
74-
#endif
7566
Py_DECREF(c_api);
7667
if (PyArray_API == NULL) {
7768
PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is NULL pointer");

numpy/core/code_generators/generate_ufunc_api.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,12 @@
4949
return -1;
5050
}
5151
52-
#if PY_VERSION_HEX >= 0x03000000
5352
if (!PyCapsule_CheckExact(c_api)) {
5453
PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCapsule object");
5554
Py_DECREF(c_api);
5655
return -1;
5756
}
5857
PyUFunc_API = (void **)PyCapsule_GetPointer(c_api, NULL);
59-
#else
60-
if (!PyCObject_Check(c_api)) {
61-
PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCObject object");
62-
Py_DECREF(c_api);
63-
return -1;
64-
}
65-
PyUFunc_API = (void **)PyCObject_AsVoidPtr(c_api);
66-
#endif
6758
Py_DECREF(c_api);
6859
if (PyUFunc_API == NULL) {
6960
PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is NULL pointer");

numpy/core/include/numpy/ndarrayobject.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ extern "C" {
4545

4646
#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \
4747
PyArray_IsZeroDim(m))
48-
#if PY_MAJOR_VERSION >= 3
4948
#define PyArray_IsPythonNumber(obj) \
5049
(PyFloat_Check(obj) || PyComplex_Check(obj) || \
5150
PyLong_Check(obj) || PyBool_Check(obj))
@@ -54,17 +53,6 @@ extern "C" {
5453
#define PyArray_IsPythonScalar(obj) \
5554
(PyArray_IsPythonNumber(obj) || PyBytes_Check(obj) || \
5655
PyUnicode_Check(obj))
57-
#else
58-
#define PyArray_IsPythonNumber(obj) \
59-
(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \
60-
PyLong_Check(obj) || PyBool_Check(obj))
61-
#define PyArray_IsIntegerScalar(obj) (PyInt_Check(obj) \
62-
|| PyLong_Check(obj) \
63-
|| PyArray_IsScalar((obj), Integer))
64-
#define PyArray_IsPythonScalar(obj) \
65-
(PyArray_IsPythonNumber(obj) || PyString_Check(obj) || \
66-
PyUnicode_Check(obj))
67-
#endif
6856

6957
#define PyArray_IsAnyScalar(obj) \
7058
(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))
@@ -248,11 +236,6 @@ NPY_TITLE_KEY_check(PyObject *key, PyObject *value)
248236
if (PyUnicode_Check(title) && PyUnicode_Check(key)) {
249237
return PyUnicode_Compare(title, key) == 0 ? 1 : 0;
250238
}
251-
#if PY_VERSION_HEX < 0x03000000
252-
if (PyString_Check(title) && PyString_Check(key)) {
253-
return PyObject_Compare(title, key) == 0 ? 1 : 0;
254-
}
255-
#endif
256239
#endif
257240
return 0;
258241
}

numpy/core/include/numpy/npy_1_7_deprecated_api.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,11 @@
6969
#define PyArray_DEFAULT NPY_DEFAULT_TYPE
7070

7171
/* These DATETIME bits aren't used internally */
72-
#if PY_VERSION_HEX >= 0x03000000
7372
#define PyDataType_GetDatetimeMetaData(descr) \
7473
((descr->metadata == NULL) ? NULL : \
7574
((PyArray_DatetimeMetaData *)(PyCapsule_GetPointer( \
7675
PyDict_GetItemString( \
7776
descr->metadata, NPY_METADATA_DTSTR), NULL))))
78-
#else
79-
#define PyDataType_GetDatetimeMetaData(descr) \
80-
((descr->metadata == NULL) ? NULL : \
81-
((PyArray_DatetimeMetaData *)(PyCObject_AsVoidPtr( \
82-
PyDict_GetItemString(descr->metadata, NPY_METADATA_DTSTR)))))
83-
#endif
8477

8578
/*
8679
* Deprecated as of NumPy 1.7, this kind of shortcut doesn't

numpy/core/include/numpy/npy_3kcompat.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
#include <Python.h>
1414
#include <stdio.h>
1515

16-
#if PY_VERSION_HEX >= 0x03000000
1716
#ifndef NPY_PY3K
1817
#define NPY_PY3K 1
1918
#endif
20-
#endif
2119

2220
#include "numpy/npy_common.h"
2321
#include "numpy/ndarrayobject.h"

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,6 @@ gentype_sizeof(PyObject *self)
12931293
return PyLong_FromSsize_t(nbytes);
12941294
}
12951295

1296-
#if PY_VERSION_HEX >= 0x03000000
12971296
NPY_NO_EXPORT void
12981297
gentype_struct_free(PyObject *ptr)
12991298
{
@@ -1307,17 +1306,6 @@ gentype_struct_free(PyObject *ptr)
13071306
PyArray_free(arrif->shape);
13081307
PyArray_free(arrif);
13091308
}
1310-
#else
1311-
NPY_NO_EXPORT void
1312-
gentype_struct_free(void *ptr, void *arg)
1313-
{
1314-
PyArrayInterface *arrif = (PyArrayInterface *)ptr;
1315-
Py_DECREF((PyObject *)arg);
1316-
Py_XDECREF(arrif->descr);
1317-
PyArray_free(arrif->shape);
1318-
PyArray_free(arrif);
1319-
}
1320-
#endif
13211309

13221310
static PyObject *
13231311
gentype_struct_get(PyObject *self)

numpy/core/src/multiarray/scalartypes.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ initialize_casting_tables(void);
1919
NPY_NO_EXPORT void
2020
initialize_numeric_types(void);
2121

22-
#if PY_VERSION_HEX >= 0x03000000
2322
NPY_NO_EXPORT void
2423
gentype_struct_free(PyObject *ptr);
25-
#else
26-
NPY_NO_EXPORT void
27-
gentype_struct_free(void *ptr, void *arg);
28-
#endif
2924

3025
NPY_NO_EXPORT int
3126
is_anyscalar_exact(PyObject *obj);

numpy/core/src/umath/_rational_tests.c.src

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,6 @@ static PyNumberMethods pyrational_as_number = {
609609
pyrational_add, /* nb_add */
610610
pyrational_subtract, /* nb_subtract */
611611
pyrational_multiply, /* nb_multiply */
612-
#if PY_MAJOR_VERSION < 3
613-
pyrational_divide, /* nb_divide */
614-
#endif
615612
pyrational_remainder, /* nb_remainder */
616613
0, /* nb_divmod */
617614
0, /* nb_power */
@@ -625,27 +622,13 @@ static PyNumberMethods pyrational_as_number = {
625622
0, /* nb_and */
626623
0, /* nb_xor */
627624
0, /* nb_or */
628-
#if PY_MAJOR_VERSION < 3
629-
0, /* nb_coerce */
630-
#endif
631625
pyrational_int, /* nb_int */
632-
#if PY_MAJOR_VERSION < 3
633-
pyrational_int, /* nb_long */
634-
#else
635626
0, /* reserved */
636-
#endif
637627
pyrational_float, /* nb_float */
638-
#if PY_MAJOR_VERSION < 3
639-
0, /* nb_oct */
640-
0, /* nb_hex */
641-
#endif
642628

643629
0, /* nb_inplace_add */
644630
0, /* nb_inplace_subtract */
645631
0, /* nb_inplace_multiply */
646-
#if PY_MAJOR_VERSION < 3
647-
0, /* nb_inplace_divide */
648-
#endif
649632
0, /* nb_inplace_remainder */
650633
0, /* nb_inplace_power */
651634
0, /* nb_inplace_lshift */

numpy/core/src/umath/ufunc_object.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -929,22 +929,9 @@ parse_ufunc_keywords(PyUFuncObject *ufunc, PyObject *kwds, PyObject **kwnames, .
929929
}
930930
}
931931
else {
932-
#if PY_VERSION_HEX >= 0x03000000
933932
PyErr_Format(PyExc_TypeError,
934933
"'%S' is an invalid keyword to ufunc '%s'",
935934
key, ufunc_get_name_cstr(ufunc));
936-
#else
937-
char *str = PyString_AsString(key);
938-
if (str == NULL) {
939-
PyErr_Clear();
940-
PyErr_SetString(PyExc_TypeError, "invalid keyword argument");
941-
}
942-
else {
943-
PyErr_Format(PyExc_TypeError,
944-
"'%s' is an invalid keyword to ufunc '%s'",
945-
str, ufunc_get_name_cstr(ufunc));
946-
}
947-
#endif
948935
return -1;
949936
}
950937
}
@@ -5068,21 +5055,12 @@ _free_loop1d_list(PyUFunc_Loop1d *data)
50685055
}
50695056
}
50705057

5071-
#if PY_VERSION_HEX >= 0x03000000
50725058
static void
50735059
_loop1d_list_free(PyObject *ptr)
50745060
{
50755061
PyUFunc_Loop1d *data = (PyUFunc_Loop1d *)PyCapsule_GetPointer(ptr, NULL);
50765062
_free_loop1d_list(data);
50775063
}
5078-
#else
5079-
static void
5080-
_loop1d_list_free(void *ptr)
5081-
{
5082-
PyUFunc_Loop1d *data = (PyUFunc_Loop1d *)ptr;
5083-
_free_loop1d_list(data);
5084-
}
5085-
#endif
50865064

50875065

50885066
/*

0 commit comments

Comments
 (0)
0