Skip to content

Commit 7913ca7

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#301 from kuyan/patch-1
More formatting fixes, link fixes
2 parents d4abefc + 2c2f25d commit 7913ca7

File tree

6 files changed

+38
-39
lines changed

6 files changed

+38
-39
lines changed

docs/dev/env.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,11 @@ Other Tools
286286
IDLE
287287
----
288288

289-
`IDLE <http://docs.python.org/library/idle.html>`_ is an integrated
290-
development environment that is part of Python standard library. It is
291-
completely written in Python and uses the Tkinter GUI toolkit. Though IDLE
292-
is not suited for full-blown development using Python, it is quite
293-
helpful to try out small Python snippets and experiment with different
294-
features in Python.
289+
:ref:`IDLE <python:idle>` is an integrated development environment that is
290+
part of Python standard library. It is completely written in Python and uses
291+
the Tkinter GUI toolkit. Though IDLE is not suited for full-blown development
292+
using Python, it is quite helpful to try out small Python snippets and
293+
experiment with different features in Python.
295294

296295
It provides the following features:
297296

docs/scenarios/cli.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ Clint
1111
docopt
1212
------
1313

14-
`docopt <http://docopt.org/>`_ is a lightweight, highly Pythonic package that allows creating command line interfaces easily and intuitively, by parsing POSIX-style usage instructions.
14+
`docopt <http://docopt.org/>`_ is a lightweight, highly Pythonic package that
15+
allows creating command line interfaces easily and intuitively, by parsing
16+
POSIX-style usage instructions.

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: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ while another would handle low-level manipulation of data. The most natural way
8383
to separate these two layers is to regroup all interfacing functionality
8484
in one file, and all low-level operations in another file. In this case,
8585
the interface file needs to import the low-level file. This is done with the
86-
`import` and `from ... import` statements.
86+
``import`` and ``from ... import`` statements.
8787

8888
As soon as you use `import` statements you use modules. These can be either built-in
8989
modules such as `os` and `sys`, third-party modules you have installed in your
@@ -106,7 +106,7 @@ Aside for some naming restrictions, nothing special is required for a Python fil
106106
to be a module, but the import mechanism needs to be understood in order to use
107107
this concept properly and avoid some issues.
108108

109-
Concretely, the `import modu` statement will look for the proper file, which is
109+
Concretely, the ``import modu`` statement will look for the proper file, which is
110110
`modu.py` in the same directory as the caller if it exists. If it is not
111111
found, the Python interpreter will search for `modu.py` in the "path"
112112
recursively and raise an ImportError exception if it is not found.
@@ -120,20 +120,20 @@ Then, the module's variables, functions, and classes will be available to the ca
120120
through the module's namespace, a central concept in programming that is
121121
particularly helpful and powerful in Python.
122122

123-
In many languages, an `include file` directive is used by the preprocessor to
123+
In many languages, an ``include file`` directive is used by the preprocessor to
124124
take all code found in the file and 'copy' it into the caller's code. It is
125125
different in Python: the included code is isolated in a module namespace, which
126126
means that you generally don't have to worry that the included code could have
127127
unwanted effects, e.g. override an existing function with the same name.
128128

129129
It is possible to simulate the more standard behavior by using a special syntax
130-
of the import statement: `from modu import *`. This is generally considered bad
131-
practice. **Using `import *` makes code harder to read and makes dependencies less
130+
of the import statement: ``from modu import *``. This is generally considered bad
131+
practice. **Using ``import *`` makes code harder to read and makes dependencies less
132132
compartmentalized**.
133133

134-
Using `from modu import func` is a way to pinpoint the function you want to
135-
import and put it in the global namespace. While much less harmful than `import
136-
*` because it shows explicitly what is imported in the global namespace, its
134+
Using ``from modu import func`` is a way to pinpoint the function you want to
135+
import and put it in the global namespace. While much less harmful than ``import
136+
*`` because it shows explicitly what is imported in the global namespace, its
137137
advantage over a simpler `import modu` is only that it will save some typing.
138138

139139
**Very bad**
@@ -166,7 +166,7 @@ Python. Readability means to avoid useless boilerplate text and clutter,
166166
therefore some efforts are spent trying to achieve a certain level of brevity.
167167
But terseness and obscurity are the limits where brevity should stop. Being
168168
able to tell immediately where a class or function comes from, as in the
169-
`modu.func` idiom, greatly improves code readability and understandability in
169+
``modu.func`` idiom, greatly improves code readability and understandability in
170170
all but the simplest single file projects.
171171

172172

@@ -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
~~~~~~~~~~~~~~~~

docs/writing/tests.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Some general rules of testing:
1616
alone, and also within the test suite, regardless of the order they are called.
1717
The implication of this rule is that each test must be loaded with a fresh
1818
dataset and may have to do some cleanup afterwards. This is usually
19-
handled by `setUp()` and `tearDown()` methods.
19+
handled by ``setUp()`` and ``tearDown()`` methods.
2020

2121
- Try hard to make tests that run fast. If one single test needs more than a
2222
few millisecond to run, development will be slowed down or the tests will not

0 commit comments

Comments
 (0)