Skip to content

Commit

Permalink
sagemathgh-37716: sage.{misc,structure}: Doctest cosmetics
Browse files Browse the repository at this point in the history
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Cherry-picked from sagemath#35095.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#37716
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed May 11, 2024
2 parents da9e038 + f8753c9 commit 5f6b085
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/sage/misc/binary_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ cdef class BinaryTree:
sage: t = BinaryTree()
sage: t.contains(1)
False
sage: t.insert(1,1)
sage: t.insert(1, 1)
sage: t.contains(1)
True
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/c3_controlled.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Depending on the linear extension `l` it was necessary to add between
one and five bases for control; for example, `216` linear extensions
required the addition of four bases::
sage: sorted(Word(stats).evaluation_sparse()) # needs sage.graphs sage.modules
sage: sorted(Word(stats).evaluation_sparse()) # needs sage.combinat sage.graphs sage.modules
[(1, 36), (2, 108), (3, 180), (4, 216), (5, 180)]
We now consider a hierarchy of categories::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/converting_dict.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r"""
Converting Dictionary
At the moment, the only class contained in this model is a key
At the moment, the only class contained in this module is a key
converting dictionary, which applies some function (e.g. type
conversion function) to all arguments used as keys.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def find_objects_from_name(name, module_name=None, include_lazy_imports=False):
:class:`~sage.misc.lazy_import.LazyImport` objects that are resolving to the
same object may be included in the output::
sage: dt.find_objects_from_name('RR', include_lazy_imports=True)
sage: dt.find_objects_from_name('RR', include_lazy_imports=True) # needs sage.rings.real_mpfr
[Real Field with 53 bits of precision,
...
Real Field with 53 bits of precision,
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def flatten(in_list, ltypes=(list, tuple), max_level=sys.maxsize):
[1, 1, 1, 2]
sage: flatten([[1,2,3], (4,5), [[[1],[2]]]])
[1, 2, 3, 4, 5, 1, 2]
sage: flatten([[1,2,3], (4,5), [[[1],[2]]]],max_level=1)
sage: flatten([[1,2,3], (4,5), [[[1],[2]]]], max_level=1)
[1, 2, 3, 4, 5, [[1], [2]]]
sage: flatten([[[3],[]]],max_level=0)
[[[3], []]]
Expand Down
6 changes: 3 additions & 3 deletions src/sage/misc/function_mangling.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ cdef class ArgumentFixer:
EXAMPLES::
sage: from sage.misc.function_mangling import ArgumentFixer
sage: def sum3(a,b,c=3,*args,**kwargs):
....: return a+b+c
sage: def sum3(a, b, c=3, *args, **kwargs):
....: return a + b + c
sage: AF = ArgumentFixer(sum3)
sage: AF.fix_to_named(1,2,3,4,5,6,f=14,e=16)
sage: AF.fix_to_named(1, 2, 3, 4, 5, 6, f=14, e=16)
((4, 5, 6), (('a', 1), ('b', 2), ('c', 3), ('e', 16), ('f', 14)))
sage: AF.fix_to_named(1,2,f=14)
((), (('a', 1), ('b', 2), ('c', 3), ('f', 14)))
Expand Down
6 changes: 3 additions & 3 deletions src/sage/misc/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def krull_dimension(x):
1
sage: krull_dimension(ZZ[sqrt(5)]) # needs sage.rings.number_field sage.symbolic
1
sage: U.<x,y,z> = PolynomialRing(ZZ,3); U
sage: U.<x,y,z> = PolynomialRing(ZZ, 3); U
Multivariate Polynomial Ring in x, y, z over Integer Ring
sage: U.krull_dimension()
4
Expand Down Expand Up @@ -1732,9 +1732,9 @@ def quotient(x, y, *args, **kwds):
EXAMPLES::
sage: quotient(5,6)
sage: quotient(5, 6)
5/6
sage: quotient(5.,6.)
sage: quotient(5., 6.)
0.833333333333333
sage: R.<x> = ZZ[]; R
Univariate Polynomial Ring in x over Integer Ring
Expand Down
11 changes: 7 additions & 4 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ def lazy_import(module, names, as_=None, *,
....: deprecation=14275)
sage: my_Qp(5) # needs sage.rings.padics
doctest:...: DeprecationWarning:
Importing my_Qp from here is deprecated; please use "from sage.rings.padics.factory import Qp as my_Qp" instead.
Importing my_Qp from here is deprecated;
please use "from sage.rings.padics.factory import Qp as my_Qp" instead.
See https://github.com/sagemath/sage/issues/14275 for details.
5-adic Field with capped relative precision 20
Expand All @@ -1096,10 +1097,12 @@ def lazy_import(module, names, as_=None, *,
....: feature=PythonModule('ppl', spkg='pplpy', type='standard'))
sage: equation # needs pplpy
<cyfunction equation at ...>
sage: lazy_import('PyNormaliz', 'NmzListConeProperties', feature=PythonModule('PyNormaliz', spkg='pynormaliz')) # optional - pynormaliz
sage: NmzListConeProperties # optional - pynormaliz
sage: lazy_import('PyNormaliz', 'NmzListConeProperties',
....: feature=PythonModule('PyNormaliz', spkg='pynormaliz'))
sage: NmzListConeProperties # optional - pynormaliz
<built-in function NmzListConeProperties>
sage: lazy_import('foo', 'not_there', feature=PythonModule('foo', spkg='non-existing-package'))
sage: lazy_import('foo', 'not_there',
....: feature=PythonModule('foo', spkg='non-existing-package'))
sage: not_there
Failed lazy import:
foo is not available.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def __mul__(self, right):
r"""
EXAMPLES::
sage: # needs sage.modules
sage: # needs scipy sage.modules
sage: A = matrix(RDF, 5, 5, 2)
sage: b = vector(RDF, 5, range(5))
sage: v = A \ b
Expand Down
16 changes: 9 additions & 7 deletions src/sage/misc/sagedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def format(s, embedded=False):
r"""noreplace
Format Sage documentation ``s`` for viewing with IPython.
This calls ``detex`` on ``s`` to convert LaTeX commands to plain
This calls :func:`detex` on ``s`` to convert LaTeX commands to plain
text, unless the directive ``nodetex`` is given in the first line
of the string.
Expand All @@ -654,13 +654,13 @@ def format(s, embedded=False):
INPUT:
- ``s`` - string
- ``embedded`` - boolean (optional, default False)
- ``s`` -- string
- ``embedded`` -- boolean (optional, default ``False``)
OUTPUT: string
Set ``embedded`` equal to True if formatting for use in the
notebook; this just gets passed as an argument to ``detex``.
Set ``embedded`` equal to ``True`` if formatting for use in the
notebook; this just gets passed as an argument to :func:`detex`.
.. SEEALSO::
Expand Down Expand Up @@ -1158,7 +1158,8 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='',
sage: s = search_src('MatRiX', path_re='matrix', interact=False); s.find('x') > 0
True
sage: s = search_src('MatRiX', path_re='matrix', interact=False, ignore_case=False); s.find('x') > 0
sage: s = search_src('MatRiX', path_re='matrix',
....: interact=False, ignore_case=False); s.find('x') > 0
False
Searches are by default restricted to single lines, but this can
Expand All @@ -1170,7 +1171,8 @@ def search_src(string, extra1='', extra2='', extra3='', extra4='',
sage: len(search_src('log', 'derivative', interact=False).splitlines()) < 40
True
sage: len(search_src('log', 'derivative', interact=False, multiline=True).splitlines()) > 70
sage: len(search_src('log', 'derivative',
....: interact=False, multiline=True).splitlines()) > 70
True
A little recursive narcissism: let's do a doctest that searches for
Expand Down
12 changes: 8 additions & 4 deletions src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,11 +1572,14 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
....: cpdef meet(categories, bint as_list = False, tuple ignore_axioms=(), tuple axioms=()): pass
....: ''')
sage: sage_getargspec(Foo.join)
FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={})
FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None,
defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={})
sage: sage_getargspec(Bar.join)
FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={})
FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None,
defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={})
sage: sage_getargspec(Bar.meet)
FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None, defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={})
FullArgSpec(args=['categories', 'as_list', 'ignore_axioms', 'axioms'], varargs=None, varkw=None,
defaults=(False, (), ()), kwonlyargs=[], kwonlydefaults=None, annotations={})
Test that :issue:`17009` is fixed::
Expand All @@ -1589,7 +1592,8 @@ def foo(x, a='\')"', b={not (2+1==3):'bar'}): return
sage: from sage.misc.nested_class import MainClass
sage: sage_getargspec(MainClass.NestedClass.NestedSubClass.dummy)
FullArgSpec(args=['self', 'x', 'r'], varargs='args', varkw='kwds', defaults=((1, 2, 3.4),), kwonlyargs=[], kwonlydefaults=None, annotations={})
FullArgSpec(args=['self', 'x', 'r'], varargs='args', varkw='kwds',
defaults=((1, 2, 3.4),), kwonlyargs=[], kwonlydefaults=None, annotations={})
In :issue:`18249` was decided to return a generic signature for Python
builtin functions, rather than to raise an error (which is what Python's
Expand Down
6 changes: 3 additions & 3 deletions src/sage/misc/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class GlobalCputime:
sage: t = cputime(subprocesses=True)
sage: P = PolynomialRing(QQ,7,'x')
sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular
sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
sage: cputime(subprocesses=True) - t # output random
0.462987
Expand Down Expand Up @@ -184,7 +184,7 @@ def __add__(self, other):
sage: t = cputime(subprocesses=True)
sage: P = PolynomialRing(QQ,7,'x')
sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular
sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
sage: cputime(subprocesses=True) + t # output random
2.798708
"""
Expand All @@ -200,7 +200,7 @@ def __sub__(self, other):
sage: t = cputime(subprocesses=True)
sage: P = PolynomialRing(QQ,7,'x')
sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular
sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
sage: gb = I.groebner_basis() # calls Singular # needs sage.libs.singular
sage: cputime(subprocesses=True) - t # output random
0.462987
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/structure/coerce.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ cpdef bint is_mpmath_type(t) noexcept:

cdef class CoercionModel:
"""
See also sage.categories.pushout
See also :mod:`sage.categories.pushout`
EXAMPLES::
Expand Down
14 changes: 9 additions & 5 deletions src/sage/structure/coerce_actions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cdef class GenericAction(Action):
This will break if we tried to use it::
sage: sage.structure.coerce_actions.GenericAction(QQ, Z6, True, check=False)
sage: GenericAction(QQ, Z6, True, check=False)
Left action by Rational Field on Ring of integers modulo 6
"""
Expand Down Expand Up @@ -172,7 +172,8 @@ def detect_element_action(Parent X, Y, bint X_on_left, X_el=None, Y_el=None):
sage: ZZx = ZZ['x']
sage: M = MatrixSpace(ZZ, 2) # needs sage.modules
sage: detect_element_action(ZZx, ZZ, False)
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring
Left scalar multiplication by Integer Ring
on Univariate Polynomial Ring in x over Integer Ring
sage: detect_element_action(ZZx, QQ, True)
Right scalar multiplication by Rational Field
on Univariate Polynomial Ring in x over Integer Ring
Expand Down Expand Up @@ -301,7 +302,8 @@ cdef class ModuleAction(Action):
sage: LeftModuleAction(QQ, ZZx)
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in x over Integer Ring
sage: LeftModuleAction(QQ, ZZxy)
Left scalar multiplication by Rational Field on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring
Left scalar multiplication by Rational Field
on Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring
The following tests against a problem that was relevant during work on
:issue:`9944`::
Expand Down Expand Up @@ -399,7 +401,8 @@ cdef class ModuleAction(Action):
sage: from sage.structure.coerce_actions import LeftModuleAction, RightModuleAction
sage: ZZx = ZZ['x']
sage: A = LeftModuleAction(ZZ, ZZx); A
Left scalar multiplication by Integer Ring on Univariate Polynomial Ring in x over Integer Ring
Left scalar multiplication by Integer Ring
on Univariate Polynomial Ring in x over Integer Ring
sage: A._repr_name_()
'scalar multiplication'
Expand Down Expand Up @@ -533,7 +536,8 @@ cdef class ModuleAction(Action):
sage: cm = sage.structure.element.get_coercion_model()
sage: cm.explain(x, 1, operator.truediv)
Action discovered.
Right inverse action by Symbolic Constants Subring on Univariate Polynomial Ring in x over Symbolic Constants Subring
Right inverse action by Symbolic Constants Subring
on Univariate Polynomial Ring in x over Symbolic Constants Subring
with precomposition on right by Conversion via _symbolic_ method map:
From: Integer Ring
To: Symbolic Constants Subring
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2860,11 +2860,11 @@ cdef class RingElement(ModuleElement):
EXAMPLES::
sage: RR(-1).abs()
sage: RR(-1).abs() # needs sage.rings.real_mpfr
1.00000000000000
sage: ZZ(-1).abs()
1
sage: CC(I).abs()
sage: CC(I).abs() # needs sage.rings.real_mpfr sage.symbolic
1.00000000000000
sage: Mod(-15, 37).abs()
Traceback (most recent call last):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/structure/factorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def _latex_(self):
-1 \cdot 2^{2} \cdot 5^{2}
sage: f._latex_()
'-1 \\cdot 2^{2} \\cdot 5^{2}'
sage: x = AA['x'].0; factor(x^2 + x + 1)._latex_() # trac 12178 # needs sage.rings.number_field
sage: x = AA['x'].0; factor(x^2 + x + 1)._latex_() # Issue #12178 # needs sage.rings.number_field
'(x^{2} + x + 1.000000000000000?)'
"""
if len(self) == 0:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def __repr__(self):
EXAMPLES::
sage: Partitions.options.display # indirect doctest # needs sage.combinat
sage: Partitions.options.display # indirect doctest # needs sage.combinat
list
"""
# NOTE: we intentionally use str() instead of repr()
Expand Down Expand Up @@ -1389,7 +1389,7 @@ def __eq__(self, other):
EXAMPLES::
sage: Partitions.options == PartitionsGreatestLE.options # indirect doctest # needs sage.combinat
sage: Partitions.options == PartitionsGreatestLE.options # indirect doctest # needs sage.combinat
True
sage: Partitions.options == Tableaux.options # needs sage.combinat
False
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/indexed_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def print_options(self, **kwds):
('sorting_key', <function ...<lambda> at ...>),
('sorting_reverse', False), ('string_quotes', True),
('tensor_symbol', None)]
sage: F.print_options(bracket='[') # reset # needs sage.modules
sage: F.print_options(bracket='[') # reset # needs sage.modules
"""
# don't just use kwds.get(...) because I want to distinguish
# between an argument like "option=None" and the option not
Expand Down Expand Up @@ -399,7 +399,7 @@ def _repr_generator(self, m):
sage: a # indirect doctest # needs sage.combinat sage.modules
2*|1, 2, 3| + 4*|3, 2, 1|
sage: QS3.print_options(**original_print_options) # reset # needs sage.combinat sage.modules
sage: QS3.print_options(**original_print_options) # reset # needs sage.combinat sage.modules
TESTS::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/structure/proof/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_flag(t=None, subsystem=None):

class WithProof():
"""
Use WithProof to temporarily set the value of one of the proof
Use :class:`WithProof` to temporarily set the value of one of the proof
systems for a block of code, with a guarantee that it will be set
back to how it was before after the block is done, even if there is an error.
Expand Down

0 comments on commit 5f6b085

Please sign in to comment.