Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assess/resolve Python 3.9 deprecation warnings #1301

Closed
nrnhines opened this issue May 22, 2021 · 6 comments
Closed

Assess/resolve Python 3.9 deprecation warnings #1301

nrnhines opened this issue May 22, 2021 · 6 comments
Labels
dev Developer Tickets
Milestone

Comments

@nrnhines
Copy link
Member

../src/nrnpython/nrnpy_nrn.cpp: In function ‘PyObject* NPySecObj_psection(NPySecObj*)’:
/home/hines/.pyenv/versions/3.9.0/include/python3.9/ceval.h:24:66: warning: ‘PyObject* PyEval_CallObjectWithKeywords(PyObject*, PyObject*, PyObject*)’ is deprecated [-Wdeprecated-declarations]
     PyEval_CallObjectWithKeywords(callable, arg, (PyObject *)NULL)
                                                                  ^
../src/nrnpython/nrnpy_nrn.cpp:831:24: note: in expansion of macro ‘PyEval_CallObject’
     PyObject* result = PyEval_CallObject(nrnpy_psection, arglist);
                        ^~~~~~~~~~~~~~~~~
/home/hines/.pyenv/versions/3.9.0/include/python3.9/ceval.h:17:43: note: declared here
 Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I see that:

hines@hines-T7500:~/neuron/unicode-error/src/nrnpython$ grep -r PyEval_Call *
nrnpy_nrn.cpp:    PyObject* result = PyEval_CallObject(nrnpy_psection, arglist);
rxd.cpp:                result = PyEval_CallObject(source[i], NULL);

There are simple replacements with

PyObject* PyObject_CallNoArgs(PyObject *callable)
PyObject* PyObject_CallObject(PyObject *callable, PyObject *args)
@nrnhines nrnhines self-assigned this May 22, 2021
@nrnhines
Copy link
Member Author

@adamjhn
What is the meaning of this in geometry3d.cpp

    int geometry3d_test_call_function(PyObject* obj) {
        printf("inside\n");
        if (obj == NULL) printf("obj is NULL\n");
        Py_INCREF(obj);
        PyEval_CallObject(obj, obj);
        return 0;
    }

Shouldn't the return value of PyEval_CallObject be checked? It seems hardly correct for me merely to replace the line with

        PyObject_CallObject(obj, obj);

just to avoid the deprecation message for Python 3.9

@ramcdougal
Copy link
Member

ramcdougal commented May 22, 2021

I assume that's test code that snuck into the repository that can be safely removed.

There shouldn't be any printfs in code used for simulation. (Also, note that Py_INCREF requires obj to be non-NULL.)

@nrnhines
Copy link
Member Author

From ninja >& temp I see that there are 42 deprecation statements of three kinds.
So I guess this issue can be expanded to deal with them all.

hines@hines-T7500:~/neuron/pyeval_callobject/build$ grep deprecate temp | sed -n 's/.*warning:'//p | sort | uniq
 ‘PyObject* PyEval_CallObjectWithKeywords(PyObject*, PyObject*, PyObject*)’ is deprecated [-Wdeprecated-declarations]
 ‘Py_ssize_t _PyUnicode_get_wstr_length(PyObject*)’ is deprecated [-Wdeprecated-declarations]
 ‘Py_UNICODE* PyUnicode_AsUnicode(PyObject*)’ is deprecated [-Wdeprecated-declarations]
 #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

@nrnhines nrnhines removed their assignment May 22, 2021
@alexsavulescu alexsavulescu added this to the Release v8.1 milestone Jun 11, 2021
@alexsavulescu alexsavulescu changed the title PyEval_CallObject is deprecated in Python 3.9 Assess/resolve Python 3.9 deprecation warnings Jun 11, 2021
@alexsavulescu alexsavulescu added the dev Developer Tickets label Jun 16, 2021
@olupton
Copy link
Collaborator

olupton commented May 24, 2022

Looks like this was addressed in a combination #1334 and #1806.

@olupton olupton closed this as completed May 24, 2022
@nrnhines
Copy link
Member Author

Is it relevant that with python3.10 and

cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=install -DPYTHON_EXECUTABLE=`which python3` -DCMAKE_BUILD_TYPE=Debug -DNRN_ENABLE_RX3D=OFF -DNRN_ENABLE_INTERVIEWS=OFF
ninja

I see at the end:

/home/hines/neuron/temp/build/src/nrnpython/setup.py:2: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.core import setup, Extension

@alexsavulescu
Copy link
Member

Is it relevant that with python3.10 and

To be tackled with: #1605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev Developer Tickets
Projects
None yet
Development

No branches or pull requests

4 participants