Skip to content

Commit 13d99d9

Browse files
author
kuyan
committed
Let Sphinx link to Python documentation.
Instead of directly linking to the relevant passages.
1 parent 8e952f0 commit 13d99d9

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

docs/writing/gotchas.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ What You Should Do Instead
6565
~~~~~~~~~~~~~~~~~~~~~~~~~~
6666

6767
Create a new object each time the function is called, by using a default arg to
68-
signal that no argument was provided (``None`` is often a good choice).
68+
signal that no argument was provided (:py:data:`None` is often a good choice).
6969

7070
.. code-block:: python
7171
@@ -137,9 +137,9 @@ is looked up in the surrounding scope at call time. By then, the loop has
137137
completed and ``i`` is left with its final value of 4.
138138

139139
What's particularly nasty about this gotcha is the seemingly prevalent
140-
misinformation that this has something to do with ``lambda``\s in Python.
141-
Functions created with a ``lambda`` expression are in no way special, and in
142-
fact the same exact behavior is exhibited by just using an ordinary ``def``:
140+
misinformation that this has something to do with :ref:`lambdas <python:lambda>`
141+
in Python. Functions created with a ``lambda`` expression are in no way special,
142+
and in fact the same exact behavior is exhibited by just using an ordinary ``def``:
143143

144144
.. code-block:: python
145145

docs/writing/structure.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Python has two kinds of built-in or user-defined types.
383383

384384
Mutable types are those that allow in-place modification
385385
of the content. Typical mutables are lists and dictionaries:
386-
All lists have mutating methods, like ``append()`` or ``pop()``, and
386+
All lists have mutating methods, like :py:meth:`list.append` or :py:meth:`list.pop`, and
387387
can be modified in place. The same goes for dictionaries.
388388

389389
Immutable types provide no method for changing their content.
@@ -464,10 +464,11 @@ should be your preferred method.
464464
foo = ''.join([foo, 'ooo'])
465465
466466
.. note::
467-
You can also use the ``%`` formatting operator to concatenate the
468-
pre-determined number of strings besides ``join()`` and ``+``. However,
469-
according to :pep:`3101`, the ``%`` operator became deprecated in
470-
Python 3.1 and will be replaced by the ``format()`` method in the later versions.
467+
You can also use the :ref:`% <python:string-formatting>` formatting operator
468+
to concatenate a pre-determined number of strings besides :py:meth:`str.join`
469+
and ``+``. However, according to :pep:`3101`, the ``%`` operator became
470+
deprecated in Python 3.1 and will be replaced by the :py:meth:`str.format`
471+
method in the later versions.
471472

472473
.. code-block:: python
473474

docs/writing/style.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ Instead, use a list comprehension:
335335
four_lists = [[] for __ in xrange(4)]
336336
337337
338-
A common idiom for creating strings is to use `join <http://docs.python.org/library/string.html#string.join>`_ on an empty string.::
338+
A common idiom for creating strings is to use :py:meth:`str.join` on an empty string.::
339339

340340
letters = ['s', 'p', 'a', 'm']
341341
word = ''.join(letters)
@@ -433,7 +433,7 @@ Check if variable equals a constant
433433
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
434434

435435
You don't need to explicitly compare a value to True, or None, or 0 - you can
436-
just add it to the if statement. See `Truth Value Testing
436+
just add it to the if statement. See :ref:`Truth Value Testing
437437
<http://docs.python.org/library/stdtypes.html#truth-value-testing>`_ for a
438438
list of what is considered false.
439439

@@ -466,8 +466,8 @@ list of what is considered false.
466466
Access a Dictionary Element
467467
~~~~~~~~~~~~~~~~~~~~~~~~~~~
468468

469-
Don't use the ``has_key`` function. Instead use ``x in d`` syntax, or pass
470-
a default argument to ``get``.
469+
Don't use the :py:meth:`dict.has_key` method. Instead, use ``x in d`` syntax,
470+
or pass a default argument to :py:meth:`dict.get`.
471471

472472
**Bad**:
473473

@@ -497,10 +497,9 @@ Short Ways to Manipulate Lists
497497

498498
`List comprehensions
499499
<http://docs.python.org/tutorial/datastructures.html#list-comprehensions>`_
500-
provide a powerful, concise way to work with lists. Also, the `map
501-
<http://docs.python.org/library/functions.html#map>`_ and `filter
502-
<http://docs.python.org/library/functions.html#filter>`_ functions can perform
503-
operations on lists using a different concise syntax.
500+
provide a powerful, concise way to work with lists. Also, the :py:func:`map`
501+
:py:func:`filter` functions can perform operations on lists using a different,
502+
more concise syntax.
504503

505504
**Bad**:
506505

@@ -540,8 +539,7 @@ operations on lists using a different concise syntax.
540539
# Or:
541540
a = map(lambda i: i + 3, a)
542541
543-
Use `enumerate <http://docs.python.org/library/functions.html#enumerate>`_ to
544-
keep a count of your place in the list.
542+
Use :py:func:`enumerate` keep a count of your place in the list.
545543

546544
.. code-block:: python
547545
@@ -552,9 +550,8 @@ keep a count of your place in the list.
552550
# 1 4
553551
# 2 5
554552
555-
The ``enumerate`` function has better readability than handling a counter
556-
manually. Moreover,
557-
it is better optimized for iterators.
553+
The :py:func:`enumerate` function has better readability than handling a
554+
counter manually. Moreover, it is better optimized for iterators.
558555

559556
Read From a File
560557
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)