Skip to content

Commit e05c608

Browse files
author
Matthias Koeppe
committed
src/sage/misc/sageinspect.py: Docstring/doctest fixes
1 parent e4a7924 commit e05c608

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/sage/misc/sageinspect.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@
105105
By :trac:`9976` and :trac:`14017`, introspection also works for interactively
106106
defined Cython code, and with rather tricky argument lines::
107107
108-
sage: cython('def foo(unsigned int x=1, a=\')"\', b={not (2+1==3):\'bar\'}, *args, **kwds): return') # needs sage.misc.cython
109-
sage: print(sage_getsource(foo)) # needs sage.misc.cython
108+
sage: # needs sage.misc.cython
109+
sage: cython('def foo(unsigned int x=1, a=\')"\', b={not (2+1==3):\'bar\'}, *args, **kwds): return')
110+
sage: print(sage_getsource(foo))
110111
def foo(unsigned int x=1, a=')"', b={not (2+1==3):'bar'}, *args, **kwds): return
111-
sage: sage_getargspec(foo) # needs sage.misc.cython
112+
sage: sage_getargspec(foo)
112113
FullArgSpec(args=['x', 'a', 'b'], varargs='args', varkw='kwds', defaults=(1, ')"', {False: 'bar'}), kwonlyargs=[], kwonlydefaults=None, annotations={})
113114
114115
"""
@@ -1473,27 +1474,20 @@ def sage_getargspec(obj):
14731474
14741475
INPUT:
14751476
1476-
``obj``, any callable object
1477+
- ``obj`` -- any callable object
14771478
14781479
OUTPUT:
14791480
1480-
An ``ArgSpec`` is returned. This is a named tuple
1481-
``(args, varargs, keywords, defaults)``.
1482-
1483-
- ``args`` is a list of the argument names (it may contain nested lists).
1484-
1485-
- ``varargs`` and ``keywords`` are the names of the ``*`` and ``**``
1486-
arguments or ``None``.
1487-
1488-
- ``defaults`` is an `n`-tuple of the default values of the last `n` arguments.
1481+
A named tuple :class:`FullArgSpec` is returned, as specified by the
1482+
Python library function :func:`inspect.getfullargspec`.
14891483
14901484
NOTE:
14911485
1492-
If the object has a method ``_sage_argspec_`` then the output of
1486+
If the object has a method ``_sage_argspec_``, then the output of
14931487
that method is transformed into a named tuple and then returned.
14941488
1495-
If a class instance has a method ``_sage_src_`` then its output
1496-
is studied to determine the argspec. This is because currently
1489+
If a class instance has a method ``_sage_src_``, then its output
1490+
is studied to determine the argspec. This is because currently
14971491
the :class:`~sage.misc.cachefunc.CachedMethod` decorator has
14981492
no ``_sage_argspec_`` method.
14991493
@@ -1503,23 +1497,28 @@ def sage_getargspec(obj):
15031497
sage: def f(x, y, z=1, t=2, *args, **keywords):
15041498
....: pass
15051499
sage: sage_getargspec(f)
1506-
FullArgSpec(args=['x', 'y', 'z', 't'], varargs='args', varkw='keywords', defaults=(1, 2), kwonlyargs=[], kwonlydefaults=None, annotations={})
1500+
FullArgSpec(args=['x', 'y', 'z', 't'], varargs='args', varkw='keywords',
1501+
defaults=(1, 2), kwonlyargs=[], kwonlydefaults=None, annotations={})
15071502
15081503
We now run sage_getargspec on some functions from the Sage library::
15091504
15101505
sage: sage_getargspec(identity_matrix) # needs sage.modules
1511-
FullArgSpec(args=['ring', 'n', 'sparse'], varargs=None, varkw=None, defaults=(0, False),
1512-
kwonlyargs=[], kwonlydefaults=None, annotations={})
1506+
FullArgSpec(args=['ring', 'n', 'sparse'], varargs=None, varkw=None,
1507+
defaults=(0, False), kwonlyargs=[], kwonlydefaults=None,
1508+
annotations={})
15131509
sage: sage_getargspec(factor)
1514-
FullArgSpec(args=['n', 'proof', 'int_', 'algorithm', 'verbose'], varargs=None, varkw='kwds', defaults=(None, False, 'pari', 0), kwonlyargs=[], kwonlydefaults=None, annotations={})
1510+
FullArgSpec(args=['n', 'proof', 'int_', 'algorithm', 'verbose'],
1511+
varargs=None, varkw='kwds', defaults=(None, False, 'pari', 0),
1512+
kwonlyargs=[], kwonlydefaults=None, annotations={})
15151513
1516-
In the case of a class or a class instance, the ``ArgSpec`` of the
1514+
In the case of a class or a class instance, the :class:`FullArgSpec` of the
15171515
``__new__``, ``__init__`` or ``__call__`` method is returned::
15181516
15191517
sage: P.<x,y> = QQ[]
15201518
sage: sage_getargspec(P) # needs sage.libs.singular
1521-
FullArgSpec(args=['base_ring', 'n', 'names', 'order'], varargs=None, varkw=None,
1522-
defaults=('degrevlex',), kwonlyargs=[], kwonlydefaults=None, annotations={})
1519+
FullArgSpec(args=['base_ring', 'n', 'names', 'order'],
1520+
varargs=None, varkw=None, defaults=('degrevlex',),
1521+
kwonlyargs=[], kwonlydefaults=None, annotations={})
15231522
sage: sage_getargspec(P.__class__) # needs sage.libs.singular
15241523
FullArgSpec(args=['self', 'x'], varargs='args', varkw='kwds', defaults=(0,),
15251524
kwonlyargs=[], kwonlydefaults=None, annotations={})
@@ -1545,13 +1544,13 @@ def sage_getargspec(obj):
15451544
FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=None,
15461545
kwonlyargs=[], kwonlydefaults=None, annotations={})
15471546
1548-
If a ``functools.partial`` instance is involved, we see no other meaningful solution
1547+
If a :func:`functools.partial` instance is involved, we see no other meaningful solution
15491548
than to return the argspec of the underlying function::
15501549
1551-
sage: def f(a,b,c,d=1):
1552-
....: return a+b+c+d
1550+
sage: def f(a, b, c, d=1):
1551+
....: return a + b + c + d
15531552
sage: import functools
1554-
sage: f1 = functools.partial(f, 1,c=2)
1553+
sage: f1 = functools.partial(f, 1, c=2)
15551554
sage: sage_getargspec(f1)
15561555
FullArgSpec(args=['a', 'b', 'c', 'd'], varargs=None, varkw=None, defaults=(1,),
15571556
kwonlyargs=[], kwonlydefaults=None, annotations={})
@@ -1565,7 +1564,7 @@ def sage_getargspec(obj):
15651564
an instance of that class does not coincide with the argspec
15661565
of its call method. That behaviour is intended, since a
15671566
decorated method appears to have the generic signature
1568-
``*args,**kwds``, but in fact it is only supposed to be called
1567+
``*args, **kwds``, but in fact it is only supposed to be called
15691568
with the arguments requested by the underlying undecorated
15701569
method. We saw an easy example above, namely ``I.groebner_basis``.
15711570
Here is a more difficult one::
@@ -1605,13 +1604,14 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
16051604
The following produced a syntax error before the patch at :trac:`11913`,
16061605
see also :trac:`26906`::
16071606
1608-
sage: sage.misc.sageinspect.sage_getargspec(r.lm) # optional - rpy2
1607+
sage: sage.misc.sageinspect.sage_getargspec(r.lm) # optional - rpy2
16091608
FullArgSpec(args=['self'], varargs='args', varkw='kwds', defaults=None,
16101609
kwonlyargs=[], kwonlydefaults=None, annotations={})
16111610
16121611
The following was fixed in :trac:`16309`::
16131612
1614-
sage: cython(''' # optional - sage.misc.cython
1613+
sage: cython( # needs sage.misc.cython
1614+
....: '''
16151615
....: class Foo:
16161616
....: @staticmethod
16171617
....: def join(categories, bint as_list = False, tuple ignore_axioms=(), tuple axioms=()): pass

0 commit comments

Comments
 (0)