本文整理汇总了Python中sage.misc.sageinspect.sage_getargspec函数的典型用法代码示例。如果您正苦于以下问题:Python sage_getargspec函数的具体用法?Python sage_getargspec怎么用?Python sage_getargspec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sage_getargspec函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: argspec
def argspec():
from sageinspect import sage_getargspec
argspec = sage_getargspec(func)
args = (argspec.args if not argspec.args is None else []) + self.options.keys()
defaults = tuple(argspec.defaults if not argspec.defaults is None else ()) \
+ tuple(self.options.values())
#Note: argspec.defaults is not always a tuple for some reason
return ArgSpec(args, argspec.varargs, argspec.keywords, defaults)
示例2: f
def f(wrapper):
update_wrapper(wrapper, wrapped, assigned=assigned, updated=updated)
wrapper._sage_src_ = lambda: sage_getsource(wrapped)
wrapper._sage_src_lines_ = lambda: sage_getsourcelines(wrapped)
#Getting the signature right in documentation by Sphinx (Trac 9976)
#The attribute _sage_argspec_() is read by Sphinx if present and used
#as the argspec of the function instead of using reflection.
wrapper._sage_argspec_ = lambda: sage_getargspec(wrapped)
return wrapper
示例3: argspec
def argspec():
argspec = sage_getargspec(func)
def listForNone(l):
return l if not l is None else []
newArgs = [self.name + opt for opt in self.options.keys()]
args = (argspec.args if not argspec.args is None else []) + newArgs
defaults = (argspec.defaults if not argspec.defaults is None else ()) \
+ tuple(self.options.values())
#Note: argspec.defaults is not always a tuple for some reason
return ArgSpec(args, argspec.varargs, argspec.keywords, defaults)
示例4: format_args
def format_args(self):
# for classes, the relevant signature is the __init__ method's
initmeth = self.get_attr(self.object, '__init__', None)
# classes without __init__ method, default __init__ or
# __init__ written in C?
if initmeth is None or initmeth is object.__init__ or not \
(inspect.ismethod(initmeth) or inspect.isfunction(initmeth)):
return None
argspec = sage_getargspec(initmeth)
if argspec[0] and argspec[0][0] in ('cls', 'self'):
del argspec[0][0]
return inspect.formatargspec(*argspec)
示例5: _sage_argspec_
def _sage_argspec_(self):
"""
Return the argument specification of the wrapped function or method.
TESTS::
sage: from sage.misc.sageinspect import sage_getargspec
sage: from sage.sets.set_from_iterator import Decorator
sage: d = Decorator()
sage: d.f = find_local_minimum
sage: sage_getargspec(d) # indirect doctest
ArgSpec(args=['f', 'a', 'b', 'tol', 'maxfun'], varargs=None, keywords=None, defaults=(1.48e-08, 500))
"""
from sage.misc.sageinspect import sage_getargspec
return sage_getargspec(self.f)
示例6: args_on_obj
def args_on_obj(self, obj):
if hasattr(obj, "_sage_argspec_"):
argspec = obj._sage_argspec_()
elif inspect.isbuiltin(obj) or inspect.ismethoddescriptor(obj):
# can never get arguments of a C function or method unless
# a function to do so is supplied
if self.env.config.autodoc_builtin_argspec:
argspec = self.env.config.autodoc_builtin_argspec(obj)
else:
return None
else:
# The check above misses ordinary Python methods in Cython
# files.
argspec = sage_getargspec(obj)
if argspec is not None and argspec[0] and argspec[0][0] in ('cls', 'self'):
del argspec[0][0]
return argspec
示例7: _sage_argspec_
def _sage_argspec_(self):
"""
Returns the argument specification for this object, which is
just the argument specification for the underlying function.
See :module:`sage.misc.sageinspect` for more information on
this convention.
EXAMPLES::
sage: from sage.parallel.decorate import Parallel
sage: p = Parallel(2)
sage: def f(x, y):
... return x + y
sage: from sage.misc.sageinspect import sage_getargspec
sage: sage_getargspec(p(f))
ArgSpec(args=['x', 'y'], varargs=None, keywords=None, defaults=None)
"""
from sage.misc.sageinspect import sage_getargspec
return sage_getargspec(self.func)
示例8: args_on_obj
def args_on_obj(obj):
if hasattr(obj, "_sage_argspec_"):
return obj._sage_argspec_()
if inspect.isbuiltin(obj) or \
inspect.ismethoddescriptor(obj):
# can never get arguments of a C function or method unless
# a function to do so is supplied
if self.env.config.autodoc_builtin_argspec:
argspec = self.env.config.autodoc_builtin_argspec(obj)
return argspec
else:
return None
argspec = sage_getargspec(obj) #inspect.getargspec(obj)
if isclassinstance(obj) or inspect.isclass(obj):
# if a class should be documented as function, we try
# to use the constructor signature as function
# signature without the first argument.
if argspec is not None and argspec[0]:
del argspec[0][0]
return argspec