void-packages/srcpkgs/sagemath/patches/trac-33842-02-python_3.11-a...

169 lines
7.4 KiB
Diff
Raw Normal View History

From 9eb08f3afde3266bbd667e196513240a0fe245f4 Mon Sep 17 00:00:00 2001
From: Matthias Koeppe <mkoeppe@math.ucdavis.edu>
Date: Tue, 25 Oct 2022 22:52:56 -0700
Subject: [PATCH] inspect.ArgSpec -> inspect.FullArgSpec
---
src/sage/misc/cachefunc.pyx | 4 ++--
src/sage/misc/decorators.py | 6 ++++--
src/sage/misc/function_mangling.pyx | 2 +-
src/sage/misc/sageinspect.py | 24 +++++++++++++-----------
4 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx
index 9fa967ce737..72042ef13d6 100644
--- a/src/sage/misc/cachefunc.pyx
+++ b/src/sage/misc/cachefunc.pyx
@@ -2818,7 +2818,7 @@ cdef class CachedMethod():
except Exception:
pass
if self.nargs == 0:
- args, varargs, keywords, defaults = sage_getargspec(f)
+ args, varargs, keywords, defaults, kwonlyargs, kwonlydefaults, annotations = sage_getargspec(f)
if varargs is None and keywords is None and len(args)<=1:
self.nargs = 1
else:
@@ -2954,7 +2954,7 @@ cdef class CachedSpecialMethod(CachedMethod):
# we need to analyse the argspec
f = self._cachedfunc.f
if self.nargs == 0:
- args, varargs, keywords, defaults = sage_getargspec(f)
+ args, varargs, keywords, defaults, kwonlyargs, kwonlydefaults, annotations = sage_getargspec(f)
if varargs is None and keywords is None and len(args)<=1:
self.nargs = 1
Caller = CachedMethodCallerNoArgs(inst, f, name=name, do_pickle=self._cachedfunc.do_pickle)
diff --git a/src/sage/misc/decorators.py b/src/sage/misc/decorators.py
index 28c52448813..311a5105739 100644
--- a/src/sage/misc/decorators.py
+++ b/src/sage/misc/decorators.py
@@ -32,7 +32,8 @@ from copy import copy
from sage.misc.sageinspect import (sage_getsource, sage_getsourcelines,
sage_getargspec)
-from inspect import ArgSpec
+
+from inspect import FullArgSpec
def sage_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES):
@@ -499,7 +500,8 @@ class options():
list(self.options))
defaults = (argspec.defaults or ()) + tuple(self.options.values())
# Note: argspec.defaults is not always a tuple for some reason
- return ArgSpec(args, argspec.varargs, argspec.keywords, defaults)
+ return FullArgSpec(args, argspec.varargs, argspec.keywords, defaults,
+ kwonlyargs=[], kwonlydefaults={}, annotations={})
wrapper._sage_argspec_ = argspec
diff --git a/src/sage/misc/function_mangling.pyx b/src/sage/misc/function_mangling.pyx
index 0ac03cf0715..e1bb7978953 100644
--- a/src/sage/misc/function_mangling.pyx
+++ b/src/sage/misc/function_mangling.pyx
@@ -116,7 +116,7 @@ cdef class ArgumentFixer:
"""
def __init__(self, f, classmethod = False):
try:
- arg_names, varargs, varkw, defaults = sage_getargspec(f)
+ arg_names, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations = sage_getargspec(f)
except AttributeError:
# This error occurs if f is defined in a Cython file and the
# source file has gone.
diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py
index fbca2defc20..a3821cb56b9 100644
--- a/src/sage/misc/sageinspect.py
+++ b/src/sage/misc/sageinspect.py
@@ -359,7 +359,7 @@ def _extract_embedded_signature(docstring, name):
docstring = L[1] if len(L) > 1 else '' # Remove first line, keep the rest
def_string = "def " + name + signature + ": pass"
try:
- return docstring, inspect.ArgSpec(*_sage_getargspec_cython(def_string))
+ return docstring, inspect.FullArgSpec(*_sage_getargspec_cython(def_string))
except SyntaxError:
docstring = os.linesep.join(L)
return docstring, None
@@ -1135,8 +1135,9 @@ def _sage_getargspec_from_ast(source):
vararg = getattr(ast_args.vararg, 'arg', None)
kwarg = getattr(ast_args.kwarg, 'arg', None)
- return inspect.ArgSpec(args, vararg, kwarg,
- tuple(defaults) if defaults else None)
+ return inspect.FullArgSpec(args, vararg, kwarg,
+ tuple(defaults) if defaults else None,
+ kwonlyargs=[], kwonlydefaults={}, annotations={})
def _sage_getargspec_cython(source):
@@ -1152,7 +1153,7 @@ def _sage_getargspec_cython(source):
OUTPUT:
- - an instance of :obj:`inspect.ArgSpec`, i.e., a named tuple
+ - an instance of :class:`inspect.FullArgSpec`, i.e., a named tuple
EXAMPLES::
@@ -1662,11 +1663,11 @@ def sage_getargspec(obj):
return sage_getargspec(obj.__call__)
if isinstance(obj, (lazy_attribute, AbstractMethod)):
source = sage_getsource(obj)
- return inspect.ArgSpec(*_sage_getargspec_cython(source))
+ return inspect.FullArgSpec(*_sage_getargspec_cython(source))
if not callable(obj):
raise TypeError("obj is not a code object")
try:
- return inspect.ArgSpec(*obj._sage_argspec_())
+ return inspect.FullArgSpec(*obj._sage_argspec_())
except (AttributeError, TypeError):
pass
# If we are lucky, the function signature is embedded in the docstring.
@@ -1682,7 +1683,7 @@ def sage_getargspec(obj):
# Note that this may give a wrong result for the constants!
try:
args, varargs, varkw = inspect.getargs(obj.__code__)
- return inspect.ArgSpec(args, varargs, varkw, obj.__defaults__)
+ return inspect.FullArgSpec(args, varargs, varkw, obj.__defaults__)
except (TypeError, AttributeError):
pass
if isclassinstance(obj):
@@ -1717,7 +1718,7 @@ def sage_getargspec(obj):
except TypeError: # happens for Python builtins
source = ''
if source:
- return inspect.ArgSpec(*_sage_getargspec_cython(source))
+ return inspect.FullArgSpec(*_sage_getargspec_cython(source))
else:
func_obj = obj
@@ -1730,7 +1731,7 @@ def sage_getargspec(obj):
except TypeError: # arg is not a code object
# The above "hopefully" was wishful thinking:
try:
- return inspect.ArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))
+ return inspect.FullArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))
except TypeError: # This happens for Python builtins
# The best we can do is to return a generic argspec
args = []
@@ -1740,7 +1741,8 @@ def sage_getargspec(obj):
defaults = func_obj.__defaults__
except AttributeError:
defaults = None
- return inspect.ArgSpec(args, varargs, varkw, defaults)
+ return inspect.FullArgSpec(args, varargs, varkw, defaults,
+ kwonlyargs=[], kwonlydefaults={}, annotations={})
def formatannotation(annotation, base_module=None):
@@ -1811,7 +1813,7 @@ def sage_formatargspec(args, varargs=None, varkw=None, defaults=None,
:func:`sage_getargspec`. Since :func:`sage_getargspec` works for
Cython functions while Python's inspect module does not, it makes
sense to keep this function for formatting instances of
- ``inspect.ArgSpec``.
+ ``inspect.FullArgSpec``.
EXAMPLES::
--
2.38.1