Skip to content

Commit 2ce5e7c

Browse files
author
Release Manager
committed
gh-39101: Add cython.binding(True) to occurrences of sage_wraps This is needed for the code to work in future Cython versions. Looks like Cython considers this a feature, not a bug: cython/cython#6555 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have created tests covering the changes. (existing tests should catch it) - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39101 Reported by: user202729 Reviewer(s): Tobias Diez
2 parents d197088 + 4e5bb7f commit 2ce5e7c

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/sage/misc/decorators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def sage_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES):
5151
the special attribute ``_sage_argspec_`` of the wrapping function (for an
5252
example, see e.g. ``@options`` decorator in this module).
5353
54+
Note that in ``.pyx`` files which is compiled by Cython, because Sage uses
55+
``binding=False`` compiler directive by default, you need to explicitly
56+
specify ``binding=True`` for all functions decorated with ``sage_wraps``::
57+
58+
sage: import cython
59+
sage: def square(f):
60+
....: @sage_wraps(f)
61+
....: @cython.binding(True)
62+
....: def new_f(x):
63+
....: return f(x)*f(x)
64+
....: return new_f
65+
5466
EXAMPLES:
5567
5668
Demonstrate that documentation string and source are retained from the

src/sage/structure/element.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,7 @@ def coerce_binop(method):
47374737
TypeError: algorithm 1 not supported
47384738
"""
47394739
@sage_wraps(method)
4740+
@cython.binding(True)
47404741
def new_method(self, other, *args, **kwargs):
47414742
if have_same_parent(self, other):
47424743
return method(self, other, *args, **kwargs)

src/sage/structure/mutability.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Mutability Cython Implementation
1212
# https://www.gnu.org/licenses/
1313
##########################################################################
1414

15+
cimport cython
1516
from sage.misc.decorators import sage_wraps
1617

1718
cdef class Mutability:
@@ -286,6 +287,7 @@ def require_mutable(f):
286287
- Simon King <[email protected]>
287288
"""
288289
@sage_wraps(f)
290+
@cython.binding(True)
289291
def new_f(self, *args, **kwds):
290292
if getattr(self, '_is_immutable', False):
291293
raise ValueError("{} instance is immutable, {} must not be called".format(type(self), repr(f)))
@@ -338,6 +340,7 @@ def require_immutable(f):
338340
- Simon King <[email protected]>
339341
"""
340342
@sage_wraps(f)
343+
@cython.binding(True)
341344
def new_f(self, *args, **kwds):
342345
if not getattr(self,'_is_immutable',False):
343346
raise ValueError("{} instance is mutable, {} must not be called".format(type(self), repr(f)))

src/sage/symbolic/expression.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ More sanity tests::
372372
# https://www.gnu.org/licenses/
373373
# ****************************************************************************
374374

375+
cimport cython
375376
from cysignals.signals cimport sig_on, sig_off
376377
from sage.ext.cplusplus cimport ccrepr, ccreadstr
377378

@@ -13574,6 +13575,7 @@ def _eval_on_operands(f):
1357413575
Some documentation.
1357513576
"""
1357613577
@sage_wraps(f)
13578+
@cython.binding(True)
1357713579
def new_f(ex, *args, **kwds):
1357813580
new_args = list(ex._unpack_operands())
1357913581
new_args.extend(args)

0 commit comments

Comments
 (0)