From 4723069f75b72c13825757c54030400403463ac3 Mon Sep 17 00:00:00 2001 From: lixiaoyong Date: Mon, 27 May 2024 03:15:47 -0400 Subject: [PATCH] Add backport-It-was-not-possible-to-update-__class__-attribute.patch --- ...ssible-to-update-__class__-attribute.patch | 75 +++++++++++++++++++ python-wrapt.spec | 7 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 backport-It-was-not-possible-to-update-__class__-attribute.patch diff --git a/backport-It-was-not-possible-to-update-__class__-attribute.patch b/backport-It-was-not-possible-to-update-__class__-attribute.patch new file mode 100644 index 0000000..35218ee --- /dev/null +++ b/backport-It-was-not-possible-to-update-__class__-attribute.patch @@ -0,0 +1,75 @@ +From fe909c26f29f954de7648f8bb7fbd1916ee34cc6 Mon Sep 17 00:00:00 2001 +From: Graham Dumpleton +Date: Fri, 23 Jun 2023 12:11:43 +1000 +Subject: [PATCH] It was not possible to update __class__ attribute via the + ObjectProxy when using C implementation. + +--- + src/wrapt/_wrappers.c | 15 ++++++++++++++- + tests/test_object_proxy.py | 18 ++++++++++++++++++ + 2 files changed, 32 insertions(+), 1 deletion(-) + +diff --git a/src/wrapt/_wrappers.c b/src/wrapt/_wrappers.c +index 7ff1085..cf35531 100644 +--- a/src/wrapt/_wrappers.c ++++ b/src/wrapt/_wrappers.c +@@ -1464,6 +1464,19 @@ static PyObject *WraptObjectProxy_get_class( + + /* ------------------------------------------------------------------------- */ + ++static int WraptObjectProxy_set_class(WraptObjectProxyObject *self, ++ PyObject *value) ++{ ++ if (!self->wrapped) { ++ PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); ++ return -1; ++ } ++ ++ return PyObject_SetAttrString(self->wrapped, "__class__", value); ++} ++ ++/* ------------------------------------------------------------------------- */ ++ + static PyObject *WraptObjectProxy_get_annotations( + WraptObjectProxyObject *self) + { +@@ -1779,7 +1792,7 @@ static PyGetSetDef WraptObjectProxy_getset[] = { + { "__doc__", (getter)WraptObjectProxy_get_doc, + (setter)WraptObjectProxy_set_doc, 0 }, + { "__class__", (getter)WraptObjectProxy_get_class, +- NULL, 0 }, ++ (setter)WraptObjectProxy_set_class, 0 }, + { "__annotations__", (getter)WraptObjectProxy_get_annotations, + (setter)WraptObjectProxy_set_annotations, 0 }, + { "__wrapped__", (getter)WraptObjectProxy_get_wrapped, +diff --git a/tests/test_object_proxy.py b/tests/test_object_proxy.py +index 50522b2..352c66b 100644 +--- a/tests/test_object_proxy.py ++++ b/tests/test_object_proxy.py +@@ -2417,5 +2417,23 @@ class TestArgumentUnpackingDecorator(unittest.TestCase): + + self.assertEqual(result, ('self', (), dict(arg1='arg1'))) + ++class TestOverridingSpecialAttributes(unittest.TestCase): ++ ++ def test_overriding_class_attribute(self): ++ class Object1: pass ++ class Object2(Object1): pass ++ ++ o1 = Object1() ++ ++ self.assertEqual(o1.__class__, type(o1)) ++ ++ o2 = Object2() ++ ++ self.assertEqual(o2.__class__, type(o2)) ++ ++ o2.__class__ = type(o1) ++ ++ self.assertEqual(o2.__class__, type(o1)) ++ + if __name__ == '__main__': + unittest.main() +-- +2.18.2 + diff --git a/python-wrapt.spec b/python-wrapt.spec index d24bb71..6646b51 100644 --- a/python-wrapt.spec +++ b/python-wrapt.spec @@ -1,12 +1,14 @@ %global _empty_manifest_terminate_build 0 Name: python-wrapt Version: 1.15.0 -Release: 1 +Release: 2 Summary: A Python module for decorators, wrappers and monkey patching License: BSD-2-Clause URL: https://github.com/GrahamDumpleton/wrapt Source0: https://github.com/GrahamDumpleton/wrapt/archive/refs/tags/%{version}.tar.gz +Patch0001: backport-It-was-not-possible-to-update-__class__-attribute.patch + %description The aim of the wrapt module is to provide a transparent object proxy for Python, which can be used as the basis for the construction of function wrappers and decorator functions. @@ -60,6 +62,9 @@ popd %doc docs/build/html %changelog +* Mon May 27 2024 lixiaoyong - 1.15.0-2 +- Add backport-It-was-not-possible-to-update-__class__-attribute.patch + * Tue Apr 04 2023 xu_ping - 1.15.0-1 - Upgrade version to 1.15.0 -- Gitee