mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-76007: Deprecate __version__ attribute in ctypes (#142679)
This commit is contained in:
parent
fb554ad68d
commit
38ad651b67
7 changed files with 53 additions and 7 deletions
|
|
@ -6334,7 +6334,6 @@ _ctypes_add_objects(PyObject *mod)
|
|||
MOD_ADD("FUNCFLAG_USE_ERRNO", PyLong_FromLong(FUNCFLAG_USE_ERRNO));
|
||||
MOD_ADD("FUNCFLAG_USE_LASTERROR", PyLong_FromLong(FUNCFLAG_USE_LASTERROR));
|
||||
MOD_ADD("FUNCFLAG_PYTHONAPI", PyLong_FromLong(FUNCFLAG_PYTHONAPI));
|
||||
MOD_ADD("__version__", PyUnicode_FromString("1.1.0"));
|
||||
|
||||
MOD_ADD("_memmove_addr", PyLong_FromVoidPtr(memmove));
|
||||
MOD_ADD("_memset_addr", PyLong_FromVoidPtr(memset));
|
||||
|
|
|
|||
|
|
@ -1990,8 +1990,32 @@ buffer_info(PyObject *self, PyObject *arg)
|
|||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
_ctypes_getattr(PyObject *Py_UNUSED(self), PyObject *args)
|
||||
{
|
||||
PyObject *name;
|
||||
if (!PyArg_UnpackTuple(args, "__getattr__", 1, 1, &name)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(name) && PyUnicode_EqualToUTF8(name, "__version__")) {
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"'__version__' is deprecated and slated for "
|
||||
"removal in Python 3.20",
|
||||
1) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return PyUnicode_FromString("1.1.0"); // Do not change
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"module '_ctypes' has no attribute %R", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
PyMethodDef _ctypes_module_methods[] = {
|
||||
{"__getattr__", _ctypes_getattr, METH_VARARGS},
|
||||
{"get_errno", get_errno, METH_NOARGS},
|
||||
{"set_errno", set_errno, METH_VARARGS},
|
||||
{"_unpickle", unpickle, METH_VARARGS },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue