Skip to content

Commit 7c52361

Browse files
author
Matthias Koeppe
committed
src/doc/en/developer/coding_in_python.rst: Fix more sphinx markup
1 parent c5530c5 commit 7c52361

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/doc/en/developer/coding_in_python.rst

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,23 @@ into the structure of Sage. In particular, much of Sage is implemented
8282
in the object-oriented language Python, and there is a hierarchy of
8383
classes that organize code and functionality. For example, if you
8484
implement elements of a ring, your class should derive from
85-
``sage.structure.element.RingElement``, rather than starting from
85+
:class:`sage.structure.element.RingElement`, rather than starting from
8686
scratch. Try to figure out how your code should fit in with other Sage
8787
code, and design it accordingly.
8888

8989

9090
Special Sage functions
9191
======================
9292

93-
Functions with leading and trailing double underscores ``__XXX__`` are
93+
Functions with leading and trailing double underscores :meth:`__XXX__` are
9494
all predefined by Python. Functions with leading and trailing single
95-
underscores ``_XXX_`` are defined for Sage. Functions with a single
95+
underscores :meth:`_XXX_` are defined for Sage. Functions with a single
9696
leading underscore are meant to be semi-private, and those with a
9797
double leading underscore are considered really private. Users can
9898
create functions with leading and trailing underscores.
9999

100100
Just as Python has many standard special methods for objects, Sage
101-
also has special methods. They are typically of the form ``_XXX_``.
101+
also has special methods. They are typically of the form :meth:`_XXX_`.
102102
In a few cases, the trailing underscore is not included, but this will
103103
eventually be changed so that the trailing underscore is always
104104
included. This section describes these special methods.
@@ -122,7 +122,7 @@ or from some other already existing Sage class:
122122
class MyFavoriteAlgebra(Parent):
123123
...
124124
125-
You should implement the ``_latex_`` and ``_repr_`` method for every
125+
You should implement the :meth:`_latex_` and :meth:`_repr_` method for every
126126
object. The other methods depend on the nature of the object.
127127

128128

@@ -132,18 +132,18 @@ LaTeX representation
132132
Every object ``x`` in Sage should support the command ``latex(x)``, so
133133
that any Sage object can be easily and accurately displayed via
134134
LaTeX. Here is how to make a class (and therefore its instances)
135-
support the command ``latex``.
135+
support the command :func:`latex`.
136136

137137
#. Define a method ``_latex_(self)`` that returns a LaTeX
138138
representation of your object. It should be something that can be
139139
typeset correctly within math mode. Do not include opening and
140140
closing $'s.
141141

142142
#. Often objects are built up out of other Sage objects, and these
143-
components should be typeset using the ``latex`` function. For
143+
components should be typeset using :func:`latex` function. For
144144
example, if ``c`` is a coefficient of your object, and you want to
145145
typeset ``c`` using LaTeX, use ``latex(c)`` instead of
146-
``c._latex_()``, since ``c`` might not have a ``_latex_`` method,
146+
``c._latex_()``, since ``c`` might not have a :meth:`_latex_` method,
147147
and ``latex(c)`` knows how to deal with this.
148148

149149
#. Do not forget to include a docstring and an example that
@@ -152,7 +152,7 @@ support the command ``latex``.
152152
#. You can use any macros included in ``amsmath``, ``amssymb``, or
153153
``amsfonts``, or the ones defined in :mod:`sage.misc.latex_macros`.
154154

155-
An example template for a ``_latex_`` method follows. Note that the
155+
An example template for a :meth:`_latex_` method follows. Note that the
156156
``.. skip`` line should not be included in your code; it is here to
157157
prevent doctests from running on this fake example.
158158

@@ -190,8 +190,8 @@ preferable because if you only define ``_repr_(self)`` and not
190190
they like. Also, some objects should print differently depending on
191191
the context.
192192

193-
Here is an example of the ``_latex_`` and ``_repr_`` functions for the
194-
``Pi`` class. It is from the file
193+
Here is an example of the :meth:`_latex_` and :meth:`_repr_` methods for the
194+
:class:`Pi` class. It is from the file
195195
:sage_root:`src/sage/symbolic/constants.py`:
196196

197197
.. CODE-BLOCK:: python
@@ -218,8 +218,8 @@ Here is an example of the ``_latex_`` and ``_repr_`` functions for the
218218
Matrix or vector from object
219219
============================
220220

221-
Provide a ``_matrix_`` method for an object that can be coerced to a
222-
matrix over a ring `R`. Then the Sage function ``matrix`` will work
221+
Provide a :meth:`_matrix_` method for an object that can be coerced to a
222+
matrix over a ring `R`. Then the Sage function :func:`matrix` will work
223223
for this object.
224224

225225
The following is from
@@ -239,8 +239,8 @@ The following is from
239239
def adjacency_matrix(self, sparse=None, boundary_first=False):
240240
...
241241
242-
Similarly, provide a ``_vector_`` method for an object that can be
243-
coerced to a vector over a ring `R`. Then the Sage function ``vector``
242+
Similarly, provide a :meth:`_vector_` method for an object that can be
243+
coerced to a vector over a ring `R`. Then the Sage function :func:`vector`
244244
will work for this object. The following is from the file
245245
:sage_root:`src/sage/modules/free_module_element.pyx`:
246246

@@ -260,7 +260,7 @@ Sage preparsing
260260
To make Python even more usable interactively, there are a number of
261261
tweaks to the syntax made when you use Sage from the commandline or
262262
via the notebook (but not for Python code in the Sage
263-
library). Technically, this is implemented by a ``preparse()``
263+
library). Technically, this is implemented by a :func:`preparse`
264264
function that rewrites the input string. Most notably, the following
265265
replacements are made:
266266

@@ -301,7 +301,7 @@ replacements are made:
301301
are very small. Large Sage integers are much more efficient than
302302
Python integers since they are implemented using the GMP C library.
303303

304-
Consult the file ``preparser.py`` for more details about Sage
304+
Consult :mod:`sage.repl.preparse` for more details about Sage
305305
preparsing, more examples involving raw literals, etc.
306306

307307
When a file ``foo.sage`` is loaded or attached in a Sage session, a
@@ -334,7 +334,7 @@ The Sage coercion model
334334

335335
The primary goal of coercion is to be able to transparently do
336336
arithmetic, comparisons, etc. between elements of distinct sets. For
337-
example, when one writes `3 + 1/2`, one wants to perform arithmetic on
337+
example, when one writes ``3 + 1/2``, one wants to perform arithmetic on
338338
the operands as rational numbers, despite the left term being an
339339
integer. This makes sense given the obvious and natural inclusion of
340340
the integers into the rational numbers. The goal of the coercion
@@ -364,29 +364,28 @@ scope variable.
364364
.. {Put a tutorial on this here}
365365
366366
Certain objects, e.g. matrices, may start out mutable and become
367-
immutable later. See the file
368-
:sage_root:`src/sage/structure/mutability.py`.
367+
immutable later. See :mod:`sage.structure.mutability`.
369368

370369

371370
The __hash__ special method
372371
============================
373372

374-
Here is the definition of ``__hash__`` from the Python reference
373+
Here is the definition of :meth:`__hash__` from the Python reference
375374
manual:
376375

377-
Called by built-in function ``hash()`` and for operations on members
378-
of hashed collections including ``set``, ``frozenset``, and
379-
``dict``. ``__hash__()`` should return an integer. The only required
376+
Called by built-in function :func:`hash` and for operations on members
377+
of hashed collections including :class:`set`, :class:`frozenset`, and
378+
:class:`dict`. :meth:`__hash__` should return an integer. The only required
380379
property is that objects which compare equal have the same hash
381380
value; it is advised to mix together the hash values of the
382381
components of the object that also play a part in comparison of
383382
objects by packing them into a tuple and hashing the tuple.
384383

385-
If a class does not define an ``__eq__()`` method it should not define
386-
a ``__hash__()`` operation either; if it defines ``__eq__()`` but not
387-
``__hash__()``, its instances will not be usable as items in hashable
384+
If a class does not define an :meth:`__eq__` method, it should not define
385+
a :meth:`__hash__` operation either; if it defines :meth:`__eq__` but not
386+
:meth:`__hash__`, its instances will not be usable as items in hashable
388387
collections. If a class defines mutable objects and implements an
389-
``__eq__()`` method, it should not implement ``__hash__()``, since the
388+
:meth:`__eq__` method, it should not implement :meth:`__hash__`, since the
390389
implementation of hashable collections requires that a key’s hash
391390
value is immutable (if the object’s hash value changes, it will be
392391
in the wrong hash bucket).
@@ -439,7 +438,7 @@ Unfortunately, in Sage we simply cannot require
439438
440439
because serious mathematics is simply too complicated for this
441440
rule. For example, the equalities ``z == Mod(z, 2)`` and
442-
``z == Mod(z, 3)`` would force ``hash()`` to be constant on the
441+
``z == Mod(z, 3)`` would force :func:`hash` to be constant on the
443442
integers.
444443

445444
The only way we could "fix" this problem for good would be to abandon
@@ -478,7 +477,7 @@ Please avoid catch-all code like this:
478477
more_code()
479478
480479
If you do not have any exceptions explicitly listed (as a tuple), your
481-
code will catch absolutely anything, including ``ctrl-C``, typos in
480+
code will catch absolutely anything, including :kbd:`Ctrl` + :kbd:`C`, typos in
482481
the code, and alarms, and this will lead to confusion. Also, this
483482
might catch real errors which should be propagated to the user.
484483

@@ -535,7 +534,7 @@ to explore the resulting integers' number-theoretic properties
535534
such as prime factorization. Exceptions should be made when
536535
there are good reasons such as performance or compatibility
537536
with Python code, for instance in methods such as
538-
``__hash__``, ``__len__``, and ``__int__``.
537+
:meth:`__hash__`, :meth:`__len__`, and :meth:`__int__`.
539538

540539
To return a Python integer ``i`` as a Sage integer, use:
541540

@@ -544,7 +543,7 @@ To return a Python integer ``i`` as a Sage integer, use:
544543
from sage.rings.integer import Integer
545544
return Integer(i)
546545
547-
To return a Sage integer ``i`` as a Python ineger, use:
546+
To return a Sage integer ``i`` as a Python integer, use:
548547

549548
.. CODE-BLOCK:: python
550549

0 commit comments

Comments
 (0)