Skip to content

Commit c7032c1

Browse files
committed
Python 3.10 doesn't look up __annotations__ in getset descr?
1 parent cb5aebe commit c7032c1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/wrapt/_wrappers.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#define WRAPT_HEAPTYPE_STRONG_TYPEREF 1
2323
#endif
2424

25+
/* Python 3.10 needs extra __annotations__ entries in PyGetSetDef of
26+
* subclasses. */
27+
#if PY_VERSION_HEX >= 0x030a0000
28+
#define WRAPT_ANNOTATIONS_GETSET_WORKAROUND 1
29+
#endif
30+
2531
/* ------------------------------------------------------------------------- */
2632

2733
typedef struct {
@@ -1701,6 +1707,10 @@ static PyGetSetDef WraptCallableObjectProxy_getset[] = {
17011707
(setter)WraptObjectProxy_set_module, 0 },
17021708
{ "__doc__", (getter)WraptObjectProxy_get_doc,
17031709
(setter)WraptObjectProxy_set_doc, 0 },
1710+
#ifdef WRAPT_ANNOTATIONS_GETSET_WORKAROUND
1711+
{ "__annotations__", (getter)WraptObjectProxy_get_annotations,
1712+
(setter)WraptObjectProxy_set_annotations, 0 },
1713+
#endif
17041714
{ NULL },
17051715
};
17061716

@@ -1912,6 +1922,10 @@ static PyGetSetDef WraptPartialCallableObjectProxy_getset[] = {
19121922
(setter)WraptObjectProxy_set_module, 0 },
19131923
{ "__doc__", (getter)WraptObjectProxy_get_doc,
19141924
(setter)WraptObjectProxy_set_doc, 0 },
1925+
#ifdef WRAPT_ANNOTATIONS_GETSET_WORKAROUND
1926+
{ "__annotations__", (getter)WraptObjectProxy_get_annotations,
1927+
(setter)WraptObjectProxy_set_annotations, 0 },
1928+
#endif
19151929
{ NULL },
19161930
};
19171931

@@ -2448,6 +2462,10 @@ static PyGetSetDef WraptFunctionWrapperBase_getset[] = {
24482462
(setter)WraptObjectProxy_set_module, 0 },
24492463
{ "__doc__", (getter)WraptObjectProxy_get_doc,
24502464
(setter)WraptObjectProxy_set_doc, 0 },
2465+
#ifdef WRAPT_ANNOTATIONS_GETSET_WORKAROUND
2466+
{ "__annotations__", (getter)WraptObjectProxy_get_annotations,
2467+
(setter)WraptObjectProxy_set_annotations, 0 },
2468+
#endif
24512469
{ "_self_instance", (getter)WraptFunctionWrapperBase_get_self_instance,
24522470
NULL, 0 },
24532471
{ "_self_wrapper", (getter)WraptFunctionWrapperBase_get_self_wrapper,
@@ -2637,6 +2655,10 @@ static PyGetSetDef WraptBoundFunctionWrapper_getset[] = {
26372655
(setter)WraptObjectProxy_set_module, 0 },
26382656
{ "__doc__", (getter)WraptObjectProxy_get_doc,
26392657
(setter)WraptObjectProxy_set_doc, 0 },
2658+
#ifdef WRAPT_ANNOTATIONS_GETSET_WORKAROUND
2659+
{ "__annotations__", (getter)WraptObjectProxy_get_annotations,
2660+
(setter)WraptObjectProxy_set_annotations, 0 },
2661+
#endif
26402662
{ NULL },
26412663
};
26422664

@@ -2747,6 +2769,10 @@ static PyGetSetDef WraptFunctionWrapper_getset[] = {
27472769
(setter)WraptObjectProxy_set_module, 0 },
27482770
{ "__doc__", (getter)WraptObjectProxy_get_doc,
27492771
(setter)WraptObjectProxy_set_doc, 0 },
2772+
#ifdef WRAPT_ANNOTATIONS_GETSET_WORKAROUND
2773+
{ "__annotations__", (getter)WraptObjectProxy_get_annotations,
2774+
(setter)WraptObjectProxy_set_annotations, 0 },
2775+
#endif
27502776
{ NULL },
27512777
};
27522778

0 commit comments

Comments
 (0)