Skip to content

Commit 5ea8db2

Browse files
author
Release Manager
committed
gh-40156: Support Cython 3.1 In Cython 3.1 binary operations are no longer wrappers, but methods. This breaks wrapperdescr_fastcall. Since this was rather hackish anyway, we replace its few uses by explicit coercions. We also switch some modules to compile with `binding=True`, this fixes many errors with 3.1. URL: #40156 Reported by: Antonio Rojas Reviewer(s): Dima Pasechnik
2 parents edbe69d + e289a45 commit 5ea8db2

File tree

15 files changed

+78
-132
lines changed

15 files changed

+78
-132
lines changed

pkgs/sagemath-categories/known-test-failures.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,6 @@
803803
"sage.cpython.type": {
804804
"ntests": 7
805805
},
806-
"sage.cpython.wrapperdescr": {
807-
"failed": true,
808-
"ntests": 0
809-
},
810806
"sage.doctest.check_tolerance": {
811807
"failed": true,
812808
"ntests": 19

src/doc/en/reference/cpython/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ internals.
1212
sage/cpython/debug
1313
sage/cpython/getattr
1414
sage/cpython/cython_metaclass
15-
sage/cpython/wrapperdescr
1615
sage/cpython/dict_del_by_value
1716

1817
.. include:: ../footer.txt

src/sage/algebras/lie_algebras/lie_algebra_element.pyx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ from cpython.object cimport Py_EQ, Py_NE, Py_GT, Py_GE
2222
from sage.misc.repr import repr_lincomb
2323
from sage.structure.element cimport have_same_parent, parent
2424
from sage.structure.coerce cimport coercion_model
25-
from sage.cpython.wrapperdescr cimport wrapperdescr_fastcall
2625
from sage.structure.element_wrapper cimport ElementWrapper
2726
from sage.structure.richcmp cimport richcmp, richcmp_not_equal
2827
from sage.data_structures.blas_dict cimport axpy, add, negate, scal
@@ -66,11 +65,28 @@ cdef class LieAlgebraElement(IndexedFreeModuleElement):
6665
"""
6766
try:
6867
# Try the normal coercion first
69-
return wrapperdescr_fastcall(IndexedFreeModuleElement.__mul__,
70-
left, (right,), <object>NULL)
68+
return IndexedFreeModuleElement.__mul__(left, right)
7169
except TypeError:
7270
pass
7371

72+
try:
73+
# Handle the case of right multiplication by scalar
74+
if isinstance(left, IndexedFreeModuleElement):
75+
R = (<IndexedFreeModuleElement>left)._parent._base
76+
x = R.coerce(right)
77+
return IndexedFreeModuleElement.__mul__(left, x)
78+
except (TypeError, KeyError):
79+
pass
80+
81+
try:
82+
# Handle the case of left multiplication by scalar
83+
if isinstance(right, IndexedFreeModuleElement):
84+
R = (<IndexedFreeModuleElement>right)._parent._base
85+
x = R.coerce(left)
86+
return IndexedFreeModuleElement.__mul__(x, right)
87+
except (TypeError, KeyError):
88+
pass
89+
7490
# Lift up to the UEA and try multiplication there
7591
# We will eventually want to lift stuff up anyways,
7692
# so just do it here.
@@ -349,11 +365,28 @@ cdef class LieAlgebraElementWrapper(ElementWrapper):
349365
"""
350366
try:
351367
# Try the normal coercion first
352-
return wrapperdescr_fastcall(ElementWrapper.__mul__,
353-
left, (right,), <object>NULL)
368+
return ElementWrapper.__mul__(left, right)
354369
except TypeError:
355370
pass
356371

372+
try:
373+
# Handle the case of right multiplication by scalar
374+
if isinstance(left, LieAlgebraElementWrapper):
375+
R = (<LieAlgebraElementWrapper>left)._parent._base
376+
x = R.coerce(right)
377+
return ElementWrapper.__mul__(left, x)
378+
except (TypeError, KeyError):
379+
pass
380+
381+
try:
382+
# Handle the case of left multiplication by scalar
383+
if isinstance(right, LieAlgebraElementWrapper):
384+
R = (<LieAlgebraElementWrapper>right)._parent._base
385+
x = R.coerce(left)
386+
return ElementWrapper.__mul__(x, right)
387+
except (TypeError, KeyError):
388+
pass
389+
357390
# Lift up to the UEA and try multiplication there
358391
# We will eventually want to lift stuff up anyways,
359392
# so just do it here.

src/sage/combinat/sloane_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8911,7 +8911,7 @@ def __getattribute__(self, name):
89118911
::
89128912
89138913
sage: sloane.__repr__
8914-
<built-in method __repr__ of Sloane object at 0x...>
8914+
<...__repr__...of Sloane object at 0x...>
89158915
sage: sloane.__name__
89168916
Traceback (most recent call last):
89178917
...

src/sage/cpython/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extension_data = {
2828
'getattr' : files('getattr.pyx'),
2929
'string' : files('string.pyx'),
3030
'type' : files('type.pyx'),
31-
'wrapperdescr' : files('wrapperdescr.pyx'),
3231
}
3332

3433
foreach name, pyx : extension_data

src/sage/cpython/wrapperdescr.pyx

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/sage/graphs/base/static_sparse_backend.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Classes and methods
3535
-------------------
3636
"""
3737

38+
cimport cython
3839
from cysignals.memory cimport check_calloc, sig_free
3940

4041
from sage.graphs.base.static_sparse_graph cimport (init_short_digraph,
@@ -1545,6 +1546,7 @@ cdef class StaticSparseBackend(CGraphBackend):
15451546
(<StaticSparseCGraph> self._cg).del_vertex(v)
15461547

15471548

1549+
@cython.binding(True)
15481550
def _run_it_on_static_instead(f):
15491551
r"""
15501552
A decorator function to force the (Di)Graph functions to compute from a

src/sage/graphs/strongly_regular_db.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ def is_complete_multipartite(int v, int k, int l, int mu):
957957
958958
sage: from sage.graphs.strongly_regular_db import is_complete_multipartite
959959
sage: t = is_complete_multipartite(12,8,4,8); t
960-
(<cyfunction is_complete_multipartite.<locals>.CompleteMultipartiteSRG at ...>,
960+
(<...CompleteMultipartiteSRG...>,
961961
3,
962962
4)
963963
sage: g = t[0](*t[1:]); g
@@ -1492,7 +1492,7 @@ def is_twograph_descendant_of_srg(int v, int k0, int l, int mu):
14921492

14931493
sage: from sage.graphs.strongly_regular_db import is_twograph_descendant_of_srg
14941494
sage: t = is_twograph_descendant_of_srg(27, 10, 1, 5); t # needs sage.rings.finite_rings
1495-
(<cyfunction is_twograph_descendant_of_srg.<locals>.la at...
1495+
(<...is_twograph_descendant_of_srg...>, (8,))
14961496
sage: g = t[0](*t[1:]); g # needs sage.rings.finite_rings
14971497
descendant of complement(Johnson graph with parameters 8,2) at {0, 1}: Graph on 27 vertices
14981498
sage: g.is_strongly_regular(parameters=True) # needs sage.rings.finite_rings
@@ -1662,9 +1662,9 @@ def is_switch_OA_srg(int v, int k, int l, int mu):
16621662
sage: t[0](*t[1:]).is_strongly_regular(parameters=True) # needs sage.schemes
16631663
(290, 136, 63, 64)
16641664
sage: is_switch_OA_srg(626, 300, 143, 144) # needs sage.schemes
1665-
(<cyfunction is_switch_OA_srg.<locals>.switch_OA_srg at ..., 12, 25)
1665+
(<...switch_OA_srg..., 12, 25)
16661666
sage: is_switch_OA_srg(842, 406, 195, 196) # needs sage.schemes
1667-
(<cyfunction is_switch_OA_srg.<locals>.switch_OA_srg at ..., 14, 29)
1667+
(<...switch_OA_srg..., 14, 29)
16681668
"""
16691669
cdef int n_2_p_1 = v
16701670
cdef int n = <int> floor(sqrt(n_2_p_1 - 1))
@@ -2920,21 +2920,21 @@ def strongly_regular_graph_lazy(int v, int k, int l, int mu=-1, bint existence=F
29202920

29212921
sage: from sage.graphs.strongly_regular_db import strongly_regular_graph_lazy
29222922
sage: g,p=strongly_regular_graph_lazy(10,6,3); g,p
2923-
(<cyfunction is_johnson.<locals>.<lambda> at ...>, 5)
2923+
(<...is_johnson...>, 5)
29242924
sage: g(p)
29252925
Johnson graph with parameters 5,2: Graph on 10 vertices
29262926
sage: g,p=strongly_regular_graph_lazy(10,3,0,1); g,p
2927-
(<cyfunction strongly_regular_graph_lazy.<locals>.<lambda> at...>,
2927+
(<...strongly_regular_graph_lazy...>,
29282928
(5,))
29292929
sage: g(p)
29302930
complement(Johnson graph with parameters 5,2): Graph on 10 vertices
29312931
sage: g,p=strongly_regular_graph_lazy(12,3,2); g,p
2932-
(<cyfunction strongly_regular_graph_lazy.<locals>.<lambda> at...>,
2932+
(<...strongly_regular_graph_lazy...>,
29332933
(3, 4))
29342934
sage: g(p)
29352935
complement(Multipartite Graph with set sizes [4, 4, 4]): Graph on 12 vertices
29362936
sage: g = strongly_regular_graph_lazy(539,250,105); g # needs sage.combinat sage.modules
2937-
(<cyfunction is_twograph_descendant_of_srg.<locals>.la at...>,
2937+
(<...is_twograph_descendant_of_srg...>,
29382938
5,
29392939
11)
29402940
sage: g[0](*g[1:]) # needs sage.combinat sage.modules

src/sage/misc/c3_controlled.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ class HierarchyElement(object, metaclass=ClasscallMetaclass):
11211121
to reconstruct an element of the hierarchy from its value::
11221122
11231123
sage: x._from_value # needs sage.graphs
1124-
Cached version of <cyfunction HierarchyElement.__classcall__.<locals>.f at ...>
1124+
Cached version of <...__classcall__...>
11251125
sage: x._from_value(x.value) is x # needs sage.graphs
11261126
True
11271127
"""

src/sage/misc/sageinspect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ def isclassinstance(obj):
202202
# Starting with Cython 3, Cython's builtin types have __module__ set
203203
# to the shared module names like _cython_3_0_0.
204204
not (isinstance(obj.__class__.__module__, str) and
205-
obj.__class__.__module__.startswith('_cython_')))
205+
obj.__class__.__module__.startswith('_cython_')) and
206+
# In Cython 3.1, they have 'member_descriptor' type
207+
'cython_function_or_method' not in str(obj.__class__.__module__))
206208

207209

208210
# Parse strings of form "File: sage/rings/rational.pyx (starting at line 1080)"

0 commit comments

Comments
 (0)