guix_mirror_bot pushed a commit to branch sage
in repository guix.

commit 917e71394a4300771545e568bc2056fa16237572
Author: Vinicius Monego <[email protected]>
AuthorDate: Sat Jul 5 22:07:08 2025 -0300

    gnu: sage: Safeguard _sage_getargspec_cython.
    
    * gnu/packages/sagemath.scm (sage)[source]: Add patch.
    * gnu/packages/patches/sage-safeguard-sage-getargspec-cython.patch: New
    file.
    * gnu/local.mk (dist_patch_DATA): Register it.
    
    Change-Id: I7dd491d29131ee1e192e7406cc46469cbd0d303f
---
 gnu/local.mk                                       |  1 +
 .../sage-safeguard-sage-getargspec-cython.patch    | 79 ++++++++++++++++++++++
 gnu/packages/sagemath.scm                          |  7 +-
 3 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 74ff7cae58..1d94003af1 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2264,6 +2264,7 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/rw-igraph-0.10.patch                    \
   %D%/packages/patches/rxvt-unicode-fix-cursor-position.patch  \
   %D%/packages/patches/s7-flint-3.patch                        \
+  %D%/packages/patches/sage-safeguard-sage-getargspec-cython.patch \
   %D%/packages/patches/sajson-for-gemmi-numbers-as-strings.patch       \
   %D%/packages/patches/sajson-build-with-gcc10.patch           \
   %D%/packages/patches/sbc-fix-build-non-x86.patch             \
diff --git a/gnu/packages/patches/sage-safeguard-sage-getargspec-cython.patch 
b/gnu/packages/patches/sage-safeguard-sage-getargspec-cython.patch
new file mode 100644
index 0000000000..19354703a7
--- /dev/null
+++ b/gnu/packages/patches/sage-safeguard-sage-getargspec-cython.patch
@@ -0,0 +1,79 @@
+From d87a60c54453763476845138133ad7da54c159a7 Mon Sep 17 00:00:00 2001
+From: user202729 <[email protected]>
+Date: Mon, 24 Mar 2025 10:38:12 +0700
+Subject: [PATCH 1/2] Safeguard _sage_getargspec_cython
+
+---
+This patch was taken from: https://github.com/sagemath/sage/pull/39776
+It will be released in version 10.7 and can be removed after the upgrade.
+
+ src/sage/misc/sageinspect.py | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py
+index 6fc0e29551f..d25f1f81820 100644
+--- a/src/sage/misc/sageinspect.py
++++ b/src/sage/misc/sageinspect.py
+@@ -1139,6 +1139,11 @@ def _sage_getargspec_cython(source):
+                     defaults=('a string', {(1, 2, 3): True}),
+                     kwonlyargs=[], kwonlydefaults=None, annotations={})
+     """
++    if not isinstance(source, str):
++        # the caller ought to ensure this, but if it forgets (e.g. passing 
None),
++        # we raise the correct exception type to avoid confusing error message
++        # and possible further hard-to-debug errors, see :issue:`39735`
++        raise TypeError
+     defpos = source.find('def ')
+     assert defpos > -1, "The given source does not contain 'def'"
+     s = source[defpos:].strip()
+
+From 21dd8224fca8a70490c754309350d08f56178809 Mon Sep 17 00:00:00 2001
+From: user202729 <[email protected]>
+Date: Thu, 27 Mar 2025 22:58:22 +0700
+Subject: [PATCH 2/2] Change to AssertionError and handle issue upstream
+
+---
+ src/sage/misc/sageinspect.py | 22 ++++++++++++----------
+ 1 file changed, 12 insertions(+), 10 deletions(-)
+
+diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py
+index b617e288b97..bb704d74075 100644
+--- a/src/sage/misc/sageinspect.py
++++ b/src/sage/misc/sageinspect.py
+@@ -1140,11 +1140,10 @@ def _sage_getargspec_cython(source):
+                     defaults=('a string', {(1, 2, 3): True}),
+                     kwonlyargs=[], kwonlydefaults=None, annotations={})
+     """
+-    if not isinstance(source, str):
+-        # the caller ought to ensure this, but if it forgets (e.g. passing 
None),
+-        # we raise the correct exception type to avoid confusing error message
+-        # and possible further hard-to-debug errors, see :issue:`39735`
+-        raise TypeError
++    assert isinstance(source, str)
++    # the caller ought to ensure this, but if it forgets (e.g. passing None),
++    # we avoid raising AttributeError to avoid confusing error message
++    # and possible further hard-to-debug errors, see :issue:`39735`
+     defpos = source.find('def ')
+     assert defpos > -1, "The given source does not contain 'def'"
+     s = source[defpos:].strip()
+@@ -1682,12 +1681,15 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
+         except TypeError:  # arg is not a code object
+             # The above "hopefully" was wishful thinking:
+             try:
+-                return 
inspect.FullArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))
++                source = sage_getsource(obj)
+             except TypeError:  # This happens for Python builtins
+-                # The best we can do is to return a generic argspec
+-                args = []
+-                varargs = 'args'
+-                varkw = 'kwds'
++                source = None
++            if source is not None:
++                return inspect.FullArgSpec(*_sage_getargspec_cython(source))
++            # The best we can do is to return a generic argspec
++            args = []
++            varargs = 'args'
++            varkw = 'kwds'
+     try:
+         defaults = func_obj.__defaults__
+     except AttributeError:
diff --git a/gnu/packages/sagemath.scm b/gnu/packages/sagemath.scm
index fbfba570f9..ec4e307ddb 100644
--- a/gnu/packages/sagemath.scm
+++ b/gnu/packages/sagemath.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2019, 2025 Andreas Enge <[email protected]>
-;;; Copyright © 2024 Vinicius Monego <[email protected]>
+;;; Copyright © 2024, 2025 Vinicius Monego <[email protected]>
 ;;; Copyright © 2025 Ricardo Wurmus <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -368,6 +368,11 @@ database.")
                     (url "https://github.com/sagemath/sage";)
                     (commit version)))
               (file-name (git-file-name name version))
+              (patches
+               ;; This patch works around a Cython issue and can be removed
+               ;; after sage 10.7 is released.  See
+               ;; https://github.com/sagemath/sage/issues/39735
+               (search-patches "sage-safeguard-sage-getargspec-cython.patch"))
               (sha256
                (base32
                 "0m2f6k6nwgyzfhf45r0kp798aimjxhpfnmsp1k03jpj9d6mhadk4"))))

Reply via email to