summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-27 12:13:01 (GMT)
committerGitHub <noreply@github.com>2024-06-27 12:13:01 (GMT)
commit49e5740135670e04ae6da7e6f52dbe380655e0f1 (patch)
tree47423e05c4f054ac6c6f1e7b42986ddb65b5b7d9 /Modules
parentc7d2b2b646f5abdbec501f63ab9b719b3db70a1f (diff)
downloadcpython-49e5740135670e04ae6da7e6f52dbe380655e0f1.zip
cpython-49e5740135670e04ae6da7e6f52dbe380655e0f1.tar.gz
cpython-49e5740135670e04ae6da7e6f52dbe380655e0f1.tar.bz2
[3.13] gh-121027: Add a future warning in functools.partial.__get__ (GH-121086) (#121092)
gh-121027: Add a future warning in functools.partial.__get__ (GH-121086) (cherry picked from commit db96edd6d1a58045196a71aff565743f493b5fbb) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_functoolsmodule.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 9dee7bf..564c271 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -197,6 +197,21 @@ partial_dealloc(partialobject *pto)
Py_DECREF(tp);
}
+static PyObject *
+partial_descr_get(PyObject *self, PyObject *obj, PyObject *type)
+{
+ if (obj == Py_None || obj == NULL) {
+ return Py_NewRef(self);
+ }
+ if (PyErr_WarnEx(PyExc_FutureWarning,
+ "functools.partial will be a method descriptor in "
+ "future Python versions; wrap it in staticmethod() "
+ "if you want to preserve the old behavior", 1) < 0)
+ {
+ return NULL;
+ }
+ return Py_NewRef(self);
+}
/* Merging keyword arguments using the vectorcall convention is messy, so
* if we would need to do that, we stop using vectorcall and fall back
@@ -514,6 +529,7 @@ static PyType_Slot partial_type_slots[] = {
{Py_tp_methods, partial_methods},
{Py_tp_members, partial_memberlist},
{Py_tp_getset, partial_getsetlist},
+ {Py_tp_descr_get, (descrgetfunc)partial_descr_get},
{Py_tp_new, partial_new},
{Py_tp_free, PyObject_GC_Del},
{0, 0}